Problem with using sp.ndimage.label to get largest object in a binary image

Hello there I'm putting together some code to grab an image with a map, colorbar, and possibly text and other elements, guess what the largest object in the image is -assuming it is the map - crop the image to the map extent, then reduce the number of colors in the map. My Jupiter notebook is at this location on GitHub: https://github.com/mycarta/rainbowbot/blob/master/crop_image_reduce_colors.i... The issue I have with this code is that: If I run it with the current test image (https://github.com/mycarta/rainbowbot/blob/master/stuff4matching_cmap_notebo...) or even a nimage with map touching the border(https://github.com/mycarta/rainbowbot/blob/master/stuff4matching_cmap_notebo...) the code seems to work. However, in the case of an image with larger blocks of text (https://github.com/mycarta/rainbowbot/blob/master/stuff4matching_cmap_notebo...) the output of [9] is an array that is all zeroes, although as far as I know it should not. Can anyone suggest why this is happening? I am sure it is something I am overlooking in my code/understanding of image processing. Thanks Matteo

Hi Matteo, It would be useful if you showed us the notebook being run with the problematic image, as well as the original. Having said that, it looks like perhaps you should replace this line: mask_sizes[0] = 0 with sizes[0] = 0 higher up. Perhaps your background is bigger than your foreground in the problem image. =) Juan. PS: Incidentally, have a look at skimage.morphology.remove_small_objects and skimage.morphology.remove_small_holes (this last one is in the just-released 0.12 version). PPS: Also incidentally, for ndimage we often use the convention "from scipy import ndimage as ndi" PPPS: Also, skimage.io.imread can directly load images from URLs. =) On Tue, Mar 8, 2016 at 3:06 AM, Matteo <matteo.niccoli@gmail.com> wrote:
Hello there
I'm putting together some code to grab an image with a map, colorbar, and possibly text and other elements, guess what the largest object in the image is -assuming it is the map - crop the image to the map extent, then reduce the number of colors in the map. My Jupiter notebook is at this location on GitHub:
https://github.com/mycarta/rainbowbot/blob/master/crop_image_reduce_colors.i...
The issue I have with this code is that: If I run it with the current test image ( https://github.com/mycarta/rainbowbot/blob/master/stuff4matching_cmap_notebo...) or even a nimage with map touching the border( https://github.com/mycarta/rainbowbot/blob/master/stuff4matching_cmap_notebo...) the code seems to work.
However, in the case of an image with larger blocks of text ( https://github.com/mycarta/rainbowbot/blob/master/stuff4matching_cmap_notebo... ) the output of [9] is an array that is all zeroes, although as far as I know it should not. Can anyone suggest why this is happening?
I am sure it is something I am overlooking in my code/understanding of image processing.
Thanks Matteo
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. To post to this group, send email to scikit-image@googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/b5e56392-b181-4f70-a090-115a1... <https://groups.google.com/d/msgid/scikit-image/b5e56392-b181-4f70-a090-115a14ffe05c%40googlegroups.com?utm_medium=email&utm_source=footer> . For more options, visit https://groups.google.com/d/optout.
participants (2)
-
Juan Nunez-Iglesias
-
Matteo