2014-01-22 189 views
0

我想填充此图像中的中心点,以便在最后是白色,其余是黑色。我正在尝试使用ndimage.binary_fill_holes(代码如下)。当我运行我的脚本时,出现错误'NoneType' object has no attribute 'astype'。我应该怎么做才能解决这个问题?使用ndimage.binary_fill_holes填充形状

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') 

enter image description here

回答

1

binary_fill_holes不返回任何东西(当然它返回None),如果你提供output阵列。试试这个:

ndimage.binary_fill_holes(mask_2, structure=np.ones((dim_x,dim_y)), origin=(75,75), 
          output=mask_2_filled) 
mask2filled = mask2filled.astype(int) 

或者你似乎可以不通过任何输出,这将节省你需要复制数组在上一行。另外请注意,在你的问题你的变量名称不匹配,即掩码与掩码2,mask_filled与mask_2_filled。

+0

感谢您的建议,事情还没有完全工作,但我希望能在正确的轨道上; - )。我更正了原始文章中的几个拼写错误的变量名称。 –

0

在最后,这是更容易比预期:以下this,唯一需要的行

mask_2_filled = ndimage.binary_fill_holes(mask_2)