Message Boards Message Boards

Intensity radial profile in circular images

Please find attached a small routine that plots the intensity profile between two points in a circular image. I'd like a routine that was able to make several radial routes, such as the example, from the center of the image to its exterior. Perhaps with an adjustable angular variation. I am very grateful for any help.

Antonio

enter image description here

Attachments:
12 Replies

Hi, If you are interested in radial data only, I suggest transforming the image into a polar representation. Then it becomes easy to display/process this data. radial data display

Here is a sample notebook for this example.

Attachments:
POSTED BY: Sebastien Roy
Posted 10 years ago
POSTED BY: Alexey Popkov

Dear Alexey, I'm still evaluating all solutions.I do not know yet what differences can be significant or not, in view of the different images that I am putting in the test. Thank you for your cooperation.

Antonio

Posted 10 years ago

One thing that I suggest you to take into account is the color profile with which your image is encoded. For the applications in physics it is crucial whether the color intensity values of your image are proportional to the actual light intensities recorded by your photoelectronic device or they are transformed into a "gamma-corrected" and hence non-additive derivatives. With non-additive values any interpolation scheme produces misleading results.

POSTED BY: Alexey Popkov

Dear Sebastien, Thank you for your cooperation with a possible solution. It seems significantly interesting. I will study the possibilities. Please could you explain me what means the variable w? and What representing each of the colored curves?

Thanks,

Antonio

POSTED BY: Sebastien Roy

Dear Alexey, Thank you very much for your efforts. I will spend some time auditioning and checking results to understand how these variations may or may not affect my bottom line.

Thank you,

Antonio

Posted 10 years ago

Antonio,

Here is a solution based on the Bresenham's algorithm implemented by halirutan:

bresenham[p0_, p1_] := Module[{dx, dy, sx, sy, err, newp},
  {dx, dy} = Abs[p1 - p0];
  {sx, sy} = Sign[p1 - p0];
  err = dx - dy;
  newp[{x_, y_}] := 
   With[{e2 = 2 err}, {If[e2 > -dy, err -= dy; x + sx, x], 
     If[e2 < dx, err += dx; y + sy, y]}];
  NestWhileList[newp, p0, # =!= p1 &, 1]
];

Since Bresenham's algorithm requires integer pixel positions for both ends of the line we have to snap the line to the pixel grid in the coordinate system used by PixelValue which differs from the standard image coordinate system by 1/2:

\[Alpha] = Pi/4;
radius = 300;

crcl = ComponentMeasurements[RegionBinarize[Dilation[img, 3], {{600, 440}}, 0.5], 
   "Centroid"];
(* centroid in the standard image coordinate system *)
center = 1 /. crcl;
(*integer position of the central pixel in the coordinate system used by PixelValue*)
centralPixelPosition = Round@N[center + 1/2];
(*integer position of the ending pixel in the coordinate system used by PixelValue*)
endingPixelPosition = Round@N[AngleVector[centralPixelPosition, {radius, \[Alpha]}]];
radialPixelPositionsBresenham = bresenham[centralPixelPosition, endingPixelPosition];
radialProfileBresenham = 
  Transpose[{Map[N@EuclideanDistance[centralPixelPosition, #] &, 
     radialPixelPositionsBresenham], PixelValue[img, radialPixelPositionsBresenham]}];

model = a/b Erfc[(-x + \[Mu])/(Sqrt[2] \[Sigma])];
fit = FindFit[radialProfileBresenham, model, {a, b, \[Mu], \[Sigma]}, x];
Row[{Show[ListLinePlot[radialProfileBresenham, ImageSize -> Medium], 
   Plot[model /. fit, {x, 0, radius}, PlotStyle -> Red, PlotRange -> All, 
    Evaluated -> True]], 
  Show[img, Epilog -> {Red, Thickness[.01], 
     Arrow[{centralPixelPosition - 1/2, endingPixelPosition - 1/2}], 
     Circle[centralPixelPosition - 1/2, radius]}, ImageSize -> Small]}]

output

Also find attached updated version of your Notebook.

Attachments:
POSTED BY: Alexey Popkov
Posted 10 years ago
POSTED BY: Alexey Popkov

Dear Alexey, All solutions are good. If you allow me I would like to add one more requirement. I have tried, but my knowledge is still not enough to solve it in a short time. It would be interesting if it were possible to use the image center (prior calculation of the centroid). Also interesting would finish line profile in a circle of radius r. I have tried adapt a small routine in attachment without success until now. Thank you anyway

Antonio

Attachments:
Posted 10 years ago

I have created a question on Mathematica.SE with more general formulation of this problem in order to find a solution with better performance: "PixelValues along a straight Line."

POSTED BY: Alexey Popkov
Posted 10 years ago

Hi Antonio,

Here is one approach:

\[Alpha] = Pi/3;
id = ImageDimensions[img];
pr = {0, #} & /@ id;
center = Mean /@ pr;
gr = Graphics[{White, AbsoluteThickness[1], 
    Line[{center, AngleVector[center, {Norm[id], \[Alpha]}]}]}, Background -> Black, 
   PlotRangePadding -> None, ImageSize -> id, PlotRange -> pr, AspectRatio -> Automatic];
mask = Binarize@Rasterize[Style[gr, Antialiasing -> False], "Image"];
radialProfile = 
  PixelValue[img, SortBy[PixelValuePositions[mask, 1], N@EuclideanDistance[center, #] &]];
Row[{ListLinePlot[radialProfile, ImageSize -> Medium], Show[img, gr /. White -> Red]}]

output

I also attach updated version of your Notebook to this post.

Attachments:
POSTED BY: Alexey Popkov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract