# How to Invert MorphologicalComponents?

It's actually the same question as here: Identify circles in Image and make list of all diameters

...but I cannot get it to work properly for this specific case, so I would be pleased for some help. I don't see where the error is.

What you see is photoresist pillars on a glass substrate. What I would like to do, is to get the mean diameter in x and y-direction as well as the mean period in x- and y-direction.

Now, instead of doing all the measurement manually, I was wondering, if maybe there is a way to automate it using mathematica ?

So, I wrote this code:

img = Import["image_01.jpg"];
binarized = MorphologicalBinarize[img, {0.3, 0.7}];
cutImage = ImageTake[binarized, {10, 680}, {0, 850}]


components = MorphologicalComponents[cutImage] //Colorize


As you can see thanks to the //Colorize, MorphologicalComponents sees the substrate as a component, but I would like to have the ellipses as components to measure them. How can I do that?

components = MorphologicalComponents[cutImage];
params = ComponentMeasurements[Image[1 - components],
{"Centroid", "SemiAxes", "Orientation"}] // Values;
HighlightImage[cutImage,
Graphics[{Red, {Point[#[[1]]], Rotate[Circle[#[[1]], #[[2]]], #[[3]]]} & /@ params}]]


params2 = ComponentMeasurements[DeleteSmallComponents@Image[1 - components],
{"Centroid", "SemiAxes", "Orientation"}] // Values;
HighlightImage[cutImage,
Graphics[{Red, {Point[#[[1]]], Rotate[Circle[#[[1]], #[[2]]], #[[3]]]} & /@ params2}]]


• Thanks a lot. I didn't know that you could do [1 - components] since 1 is an integer and components a matrix. But it seems to be working fine ! Thanks a lot ! Feb 12, 2019 at 13:31
• @james, you are most welcome.
– kglr
Feb 12, 2019 at 13:32
• Mathamtica is so streight-forward. Hmm, how am I going to delete all the small components in my image ? Ah, yes, 'DeleteSmallComponents' will do the trick. Nice! Feb 12, 2019 at 13:34
• You don't need MorphologicalComponents here, ComponentMeasurements[1 - cutImage will do the same thing Feb 12, 2019 at 13:56
• Thank you, @NikiEstner. Great point.
– kglr
Feb 12, 2019 at 13:59