# Integration of incomplete rings (ellipses) pattern

I am facing a problem in trying to do a series of averages in incomplete images. I have a series of X-ray data images, like this one:

As you can see my image is a series of partial rings/ellipses each with a different brightness (intensity) and width, but a common center. I would need to:

1) find the common center for all the partial rings/ellipses. This is somewhat similar to this case Find radii of concentric circles in image, but I cannot overcome the problem of having the center of the ring outside my image area.

2) Once the common center is found I would need to add up the Intensity along the visible ring part, in order to create ListPlot of the intensity VS the distance from this center, such as this example: .

Thanks a lot!

• Just to check my understanding: So you need to 1) Identify each ring and 2) Calculate its (mean) radius Dec 14, 2015 at 13:33
• Indeed I have to identify each ring, once I have the rings, I would need to Integrate (better Total) along the visible part of the ring. My aim is at the end to have a Plot showing the integrated intensity VS distance from the center. Dec 14, 2015 at 13:39
• Just to add an extra input, that I just realized. The geometry of the real X-ray experiment is such that the "ring" are actually not perfect circles but most likely ellipses. Sorry for not having specified since the beginning but the experiment is so involved that I did not realized sooner. Dec 14, 2015 at 14:39
• @MatteoS So I guess "I would need to do the radial average" needs some further explanation Dec 14, 2015 at 14:59
• @belisariushassettled: you are right, it was too short explanation. I have edited the question, hopefully is more clear now. Dec 14, 2015 at 15:11

How certain are you that these actually are concentric circles?

Here's my first try. Using some creative image processing, I've managed to reduce the rings to 1-pixel wide lines:

img = Import["http://i.stack.imgur.com/mJALq.png"];

filtered = CurvatureFlowFilter[img, 10];
thin = Thinning[
MorphologicalBinarize[
Image[Rescale[
ImageData[filtered]/GaussianFilter[ImageData[img], 25]]]]]


The idea is then to use FindMinimum to find a center and radii that minimize the mean point - circle distance for all connected components:

comp = MorphologicalComponents[DeleteSmallComponents[thin, 50]];
pts = Table[PixelValuePositions[Image[comp], i], {i, Max[comp]}];


Each connected component gets its own radius variable:

radiiVars = Array[r, Length[pts]];


But they all share the same center:

center = {cx, cy};

Function[{p, r}, Module[{centerDistSqr},
centerDistSqr = SquaredEuclideanDistance[center, #] & /@ p;

actCenter = center /. sol;


The optimal center found this way is more or less where you would expect it, but the circles won't fit:

radiusRange = MinMax[Norm[# - actCenter] & /@ Flatten[pts, 1]];
angleRange = MinMax[ArcTan @@ (# - actCenter) & /@ Flatten[pts, 1]];

Show[img,
Graphics[{Red, Circle[actCenter, #] & /@ (Abs[radiiVars /. sol])}]]


It looks as if for the circles near the bottom of the image, the center is too far left, while for the circles near the top it's too far right. Is it possible that these circles aren't really concentric (and FindMinimum finds the best-fit center somewhere in the middle of the actual centers)?

ImageTransformation[img, {Cos[#[[1]]], Sin[#[[1]]]} #[[2]] +
actCenter &, {400, 200}, DataRange -> Full,


Add: I also tried to fit ellipses with the same center, aspect ratio, rotation to the points, but it's still not a perfect fit:

conicSection = {{1, a12}, {a12, a22}};

Function[{p, r}, Module[{centerDistSqr},
centerDistSqr = (# - center).conicSection.(# - center) & /@ p;

sol = FindMinimum[cost,
actCenter = center /. sol;

Show[img,
ContourPlot[({x, y} - center).conicSection.({x, y} - center) /.
sol, {x, 0, 500}, {y, 0, 300}, MeshFunctions -> {#3 &},
Mesh -> {Abs[(radiiVars)^2 /. sol]}, MeshStyle -> {Red},

• MinMax is new in 10.3 I think. You can define it simply as {Min[#], Max[#]}& Dec 14, 2015 at 15:55