Clustering a binary image

I looked for a way to cluster a binary image and came across nilearn.regions.connected_regions and its keyword argument extract_type = 'connected_components'. The clustering seems to work fine (I guess?..Confirmations on this method and/or general approaches for clustering binary images are greatly appreciated), but from the documentation it’s not clear to me which specific algorithm is used for that. From the source code of nilearn.regions.connected_regions it seems that scipy.ndimage.label is used behind the scenes, is that correct? Nilearn’s documentation on that is a little bit sparse:

If ‘connected_components’, each component/region in the image is extracted automatically by labelling each region based upon the presence of unique features in their respective regions.

binary_image clustered_binary_image

Yes that seems to be the case, I think your interpretation is correct. So the ndimage.label documentation and examples are a bit more helpful, and for a binary image it will give a different label for each connected component.

I agree that the nilearn documentation is cryptic, a PR to fix it would be welcome!

1 Like

Thanks Jérôme, as soon as I have some time, I will send a PR :slight_smile:

1 Like