Consistent pixel assignments in ClusteringComponents?

Mathematica Asked by Christopher Moore on December 18, 2020

I have a large dataset of SEM micrographs I am trying to binarily segment via ClusteringComponents, and it has seemed to be the most accurate method compared to the other binarization functions, e.g. Morphological Binarize.

However, while the clusters are accurate, it assigns the dark or light pixel groups in essentially random order. However I suspect that it occurs when the contrast is low.

I am able to reproduce this problem with example images. On the first image, the dark pixels are assigned 0, while on the second image, the light pixels are assigned 0.


enter image description here

Image[clustered - 1, "Bit"]

enter image description here


enter image description here


enter image description here

How can I get it so it consistently assigns the dark pixel components to either 0 or 1??

One Answer

OK so I'm gonna post my jerry-rigged solution so far:

  1. Use the binarized cluster image to generate a mask of the original image

  2. Testing the mean pixel intensity of the masked area vs global mean to check if the black clusters match up with the dark areas

  3. Conditionally ColorNegate the values that don't match

    clusterColorTestFunction[testImage_] := 
    mask=Image[clustered - 1, "Bit"];
    Which[globalMean>maskedMean,ColorNegate[mask],globalMean <maskedMean,mask]

enter image description here

However, if there is a solution within the Clustering functionality I would love to hear it

Answered by Christopher Moore on December 18, 2020

Add your own answers!

Related Questions

Summation over elements

2  Asked on May 4, 2021 by madhurima-chakraborty


Find Fit error 4P logistic

1  Asked on May 3, 2021 by user76744


Changing LabelingFunction Color

2  Asked on May 3, 2021 by john-swartz


NIntegrate gives large value as result

1  Asked on May 3, 2021 by illlusion5


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir