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

Matteo matteo.niccoli at gmail.com
Tue Mar 8 09:59:36 EST 2016


Hello Juan

Thanks for your reply.
Here is a second notebook with the problem image to look at. 
https://github.com/mycarta/rainbowbot/blob/master/crop_image_reduce_colors_text_test.ipynb

I have not had time to change anything except for running it, and won't be 
able until tonight. When I do, I will look into your suggestions, and 
recommendations, and any other comments you may have from seeing the 
notebook.
But, so, the background counts when it comes to labeling/size? I had 
assumed the operations would only apply to bright elements, that's the 
misunderstanding.

Also, being here, the way, is there a better way, or a dedicated operation, 
to get the largest object/blob in a binary image?

Cheers,
Matteo

On Monday, March 7, 2016 at 11:18:25 PM UTC-7, Juan Nunez-Iglesias wrote:
>
> 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.... at gmail.com <javascript:>
> > 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.ipynb
>>
>> 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_notebooks/test1.png) 
>> or even a nimage with map touching the border(
>> https://github.com/mycarta/rainbowbot/blob/master/stuff4matching_cmap_notebooks/test2.png) 
>> 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_notebooks/test_with_text.png
>> ) 
>> 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... at googlegroups.com <javascript:>.
>> To post to this group, send email to scikit... at googlegroups.com 
>> <javascript:>.
>> To view this discussion on the web, visit 
>> https://groups.google.com/d/msgid/scikit-image/b5e56392-b181-4f70-a090-115a14ffe05c%40googlegroups.com 
>> <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.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20160308/ac102f83/attachment.html>


More information about the scikit-image mailing list