我想要填充这张图片的中心区域,这样最后的部分是白色的,其余的是黑色的。我正在尝试使用ndimage.binary_fill_holes (下面的代码)来实现它。当我运行我的脚本时,我得到了错误'NoneType' object has no attribute 'astype'。我应该怎么做才能解决这个问题?
mask_filled = np.array(mask,numpy.uint16)
ndimage.binary_fill_holes(mask_2, structure=np.ones((dim_x,dim_y)), origin=(75,75), output=mask_2_filled).astype(int)
np.savetxt(filename_filled, mask_filled, fmt='%i')

发布于 2014-01-23 03:23:34
如果提供output数组,则binary_fill_holes不返回任何内容(它返回None)。试试这个:
ndimage.binary_fill_holes(mask_2, structure=np.ones((dim_x,dim_y)), origin=(75,75),
output=mask_2_filled)
mask2filled = mask2filled.astype(int)或者看起来你可以根本不传递任何输出,这将省去你需要复制前一行的数组。还要注意,在你的问题中,你的变量名不匹配,即mask和mask2,mask_filled和mask_2_filled。
发布于 2014-01-23 05:06:39
最后,它比预期的要简单:在this之后,唯一需要的代码行是
mask_2_filled = ndimage.binary_fill_holes(mask_2)https://stackoverflow.com/questions/21291197
复制相似问题