Message Boards Message Boards

0
|
20868 Views
|
12 Replies
|
2 Total Likes
View groups...
Share
Share this post:

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 9 years ago

Probably it is worth to mention that with your approach you obtain an interpolated radial intensity values, not the actual pixel intensity values from the original image. This difference is subtle and may be OK or may be not depending on the final goal. Both my solutions produce radial profile consisting from actual pixel intensity values of the original image, no interpolation is used.

You may be interested in this solution which is also based on ImageTransformation but takes care to avoid interpolation. The only drawback is that it does not allow to get the actual distances between the pixels and the center (these distances are not uniform in the general case). Again, it may be OK depending on what the final goal is.

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 9 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

Sorry for the lack of labels.... "a" is the angle of the line, "w" is the width (in degrees) of the section of the image. If you modify the parameters in the Manipulate, you will see immediately how they relate to the radial section of the image.

The curves are: Min, Max, and Mean of the data, summed over the angular width w, for each radius (from 0 to 500 here). The bottom curve (in red) is the Standard Deviation of the data for each radius.

The idea was to demonstrate that once the image is transformed in polar coordinates, you can compute a lot of useful radial information in real time.

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

Hi Antonio,

Probably you haven't read carefully the linked thread where some conclusions were drawn:

1) My implementation in the above answer does not take into account the fact that the pixels found by that routine have distributed non-uniformly from the center. This answer of mine demonstrates the problem and provides a solution.

2) The above answer of mine is based on Mathematica's Rasterize function which (as I found later) has a bug. In the linked answer I provide a workaround based on Bresenham's algorithm which has much better performance and gives more correct results.

The Bresenham's algorithm is the key to obtain the ultimate solution to your problem. It has significant limitation which I stress in the linked answer. If the limitation isn't acceptable, you need a sub-pixel rendering algorithm.

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