0

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

enter image description here

albus_c
  • 6,292
  • 14
  • 36
  • 77

2 Answers2

1

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)

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.

Bi Rico
  • 25,283
  • 3
  • 52
  • 75
  • Thanks for the suggestion, things are not yet fully working, but I hope to be on the right track ;-). I corrected a few misspelled variables name in the original post. – albus_c Jan 22 '14 at 20:57
0

At the end, it was easier than expected: following this, the only line required is

mask_2_filled = ndimage.binary_fill_holes(mask_2)
Community
  • 1
  • 1
albus_c
  • 6,292
  • 14
  • 36
  • 77