6
$\begingroup$

I have to calculate the difference in diameter of two concentric circles. The image is obtained from an experiment and the data looks like this.enter image description here

The length required is the value of l as marked in this figure.enter image description here

For the calculation, it is required to calculate the value of l at each point and then calculate the average l over the entire 2*Pi angle. This averaging is necessary for the calculation. To calculate the average value of l averaged over the entire 2*Pi angle, I have first cleared the image and then obtained the binarized image as shown.enter image description here

However, I cannot calculate the value of the length l. Since I am new to Mathematica help will be highly appreciated.

$\endgroup$
10
$\begingroup$

The key idea to make this simpler is to apply a polar transform:

img = Import["http://i.stack.imgur.com/Y6oab.gif"];

center = 0.5 ImageDimensions[img];
maxR = 200;
polarToCart = center + {Cos[#[[1]]], Sin[#[[1]]]}*#[[2]] &;

polar = ImageTransformation[Binarize[img], polarToCart, {360, maxR}, 
  PlotRange -> {{0, 2 \[Pi]}, {0, maxR}}, DataRange -> Full]

enter image description here

Now you can just process any column in this image to find the radii at different angles. The simplest thing that can work is to just count the white pixels:

ListLinePlot[Total /@ Transpose[ImageData[polar]]]

enter image description here

Depending on your data, you might want to count the longest run of white pixels instead (using Split) or you might want to take a distance transform before applying the polar transform.

|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ very beautiful solution! $\endgroup$ – Dr. Wolfgang Hintze Feb 20 '15 at 11:18
5
$\begingroup$

This is not an area I am familiar with but for fun here is approximation of the average thickness of annular region. This uses a lot version 10 functionality.

Importing the image:

img = Import["http://i.stack.imgur.com/7BQEI.jpg"]

Using coordinate tools to calibrate image (cal is collected end points of ruler):

cal = {{1000.`, 9.333333333333314`}, {898.6666666666666`, 
    7.333333333333314`}};
cf[x_] := 25 x/EuclideanDistance @@ cal

Applying EdgeDetect to a cropped version of image:

enter image description here

Finding a circle that separate bounding circles:

Manipulate[
 Show[ListPlot[PixelValuePositions[crop, 1]], 
  Graphics[Circle[{c1, c2}, r]]], {c1, 100, 300}, {c2, 100, 300}, {r, 
  50, 200}]

enter image description here

Fitting circles and determining different in radii:

reg = PixelValuePositions[crop, 1];
ir = ImplicitRegion[(x - 200)^2 + (y - 160)^2 < 103^2, {x, y}];
inner = Pick[reg, RegionMember[ir, #] & /@ reg, True];
outer = Pick[reg, RegionMember[ir, #] & /@ reg, False];
lfi = LinearModelFit[{#1, #2, #2^2 + #1^2} & @@@ inner, {x, y}, {x, 
    y}];
func[x_, y_] := lfi["BestFitParameters"].{1, x, y} - y^2 - x^2;
lfo = LinearModelFit[{#1, #2, #1^2 + #2^2} & @@@ outer, {x, y}, {x, 
    y}];
funco[x_, y_] := lfo["BestFitParameters"].{1, x, y} - y^2 - x^2;
cni = RegionCentroid[i = ImplicitRegion[func[x, y] == 0, {x, y}]]
cno = RegionCentroid[o = ImplicitRegion[funco[x, y] == 0, {x, y}]]
rado = RegionMeasure[o]/(2 Pi);
radi = RegionMeasure[i]/(2 Pi);
cf[rado - radi]

This yielded inner circle centre, outer circle centre and different in radi (in microns):

enter image description here

Looking at models:

lfi["ParameterTable"]
lfo["ParameterTable"]

enter image description here

and visualizing:

Show[Graphics[{Red, Thick, Dashed, Circle[cni, radi], Green, 
   Circle[cno, rado]}], ListPlot[{inner, outer}], Frame -> True]

enter image description here

The model assumes a circle. I look forward to better answers and corrections of likely misconceptions I have wrt image analysis.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.