# Removing outer concentric circle picked up by ComponentMeasurement

So I have performed EdgeDetect and ComponentMeasurements on my images and obtained a pretty good elliptical fit. However, the black shadow of the beads in the image is being picked up by ComponentMeasurement. Is there a way to remove this larger outer (almost concentric ellipse) from the matrix returned by ComponentMeasurement?

This is my current code for ComponentMeasurement. Would it be feasible to implement a filter for what I've described within the code for ComponentMeasurement itself?

pic = Import[...];
picEdge = Image[EdgeDetect[pic, 9]];
params2 = ComponentMeasurements[picEdge, {"Centroid", "SemiAxes","Orientation", "Elongation"}, #Elongation < .5 && #Width > 3 && #Length < 70 &] // Values;


I was thinking of finding Centroid coordinates that are relatively close by, and comparing semi-axis lengths to remove the larger ellipse from the matrix, but I'm still relatively new to Mathematica and I'm not sure how to go about doing this.

Thanks all!

Original Image:

Map[First][
Sort[#, (Norm[#1[[2]]] < Norm[#2[[2]]] &)] & /@
Gather[params2, Norm[#1[[1]] - #2[[1]]] < 15 &]
]


I'd recommend reading this expression from the inside out. The core of this is Gather, which is used to group the nearly concentric elements together using the test function Norm[#1[[1]] - #2[[1]]] < 15 &. This function can be read as "Is the distance between the position of group 1 and the center of group 2 less than 15 pixels?"

Then we Sort each resulting sub list (with /@ to map the specific sort function over each element) so that the smallest circle is at the front of each of them (by taking the Norm of the semi-axes). Then we use Map[First][ ... ] to select the first element of each group, so that we select only the smallest element of each.

• Thanks eyorble, your code worked great! Just wondering, does Gather compare consecutive elements to group them, or does it compare a single element against all the other elements in that set? – Gnaprs Feb 11 '18 at 2:38
• @Gnaprs I would guess that it compares each element to each successive element in the list that isn't already in a group, but I do not actually know at present. If I get the opportunity I'll look into it further. – eyorble Feb 11 '18 at 7:17
• @Gnaprs It looks like it works like I said, compare the outputs of Gather[{5/2, 1, 2, 5, 6, 3}, Abs[#1 - #2] <= 1 &] and Gather[{1, 2, 5, 6, 3, 5/2}, Abs[#1 - #2] <= 1 &]. – eyorble Feb 11 '18 at 8:34