问题描述
我想在此图像中填充中心点,以使末尾为白色,其余为黑色.我正在尝试使用ndimage.binary_fill_holes
(下面的代码)做到这一点.运行脚本时,出现错误'NoneType' object has no attribute 'astype'
.我应该怎么做才能解决这个问题?
I want to fill the central spot in this image, so that at the end that is white and the rest is black. I am trying to do it using ndimage.binary_fill_holes
(code below). When I run my script, I get the error 'NoneType' object has no attribute 'astype'
. What should I do to fix this?
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')
推荐答案
binary_fill_holes
不返回任何内容(它返回None
).试试这个:
binary_fill_holes
doesn't return anything (well it returns None
) if you provide the output
array. Try this:
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 vs mask2,mask_filled vs mask_2_filled.
Or it seems like you could just not pass any ouput at all, that would save you needing to copy the array in the previous line. Also notice that in your question your variable names don't match, ie mask vs mask2, mask_filled vs mask_2_filled.
这篇关于使用ndimage.binary_fill_holes填充形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!