Filter löschen
Filter löschen

How to plot the radial profile of a 2D image

46 Ansichten (letzte 30 Tage)
Maura Monville
Maura Monville am 31 Mär. 2016
Beantwortet: Sergey Loginov am 5 Nov. 2021
My goal is to plot the image values (interpolated but not averaged) along an arbitrary diameter (arbitrary azimuth angle). I have attached my attempt to do that but it only works for 1/2 the diameter and only for square (nxn) images. Furthermore, it fails on some test images, even if represented by a squared array, printing the following error that I cannot interpret:
>> sampled_radial_slice = interp2(X,Y,img,x,y); Error using griddedInterpolant Sample values must be a single or double array. Error in interp2>makegriddedinterp (line 228) F = griddedInterpolant(varargin{:}); Error in interp2 (line 136) F = makegriddedinterp(X, Y, V, method,extrap);
I would like to extend this script to rectangular 2D images and to plot the profile along a diameter not just a radius for arbitrary azimuthal angle. The diameter should pass through the image center. Any suggestion and helpis welcome. Thank you in advance. maura

Antworten (4)

Image Analyst
Image Analyst am 31 Mär. 2016
Bearbeitet: Image Analyst am 25 Jan. 2019
See attached demo to get the average radial profile.
  8 Kommentare
Image Analyst
Image Analyst am 29 Jan. 2019
Yes, you can oversample like I, and you, said. In other words, just have a larger matrix and you'll have a lot more samples and higher precision.
alic rou
alic rou am 14 Jul. 2020
Bearbeitet: alic rou am 14 Jul. 2020
Worked great for me. Thank you.

Melden Sie sich an, um zu kommentieren.


Hugo Trentesaux
Hugo Trentesaux am 7 Feb. 2019
The proposed function seems very complicated to me. Here is my version :
function profile = radialAverage(IMG, cx, cy, w)
% computes the radial average of the image IMG around the cx,cy point
% w is the vector of radii starting from zero
[a,b] = size(IMG);
[X, Y] = meshgrid( (1:a)-cx, (1:b)-cy);
R = sqrt(X.^2 + Y.^2);
profile = [];
for i = w % radius of the circle
mask = (i-1<R & R<i+1); % smooth 1 px around the radius
values = (1-abs(R(mask)-i)) .* double(IMG(mask)); % smooth based on distance to ring
% values = IMG(mask); % without smooth
profile(end+1) = mean( values(:) );
end
end

Maura Monville
Maura Monville am 5 Apr. 2016
I would like someone to explain to me:
1. Matlab pixel indices convention. That is growing direction of row index and growing direction of column index
2. How to convert cartesian coordinates, centered in the image center, to pixel coordinates
Thank you in advance. maura.monville@gmail.com
  2 Kommentare
Image Analyst
Image Analyst am 5 Apr. 2016
1. When linear indexing, it goes down rows first, then over column-by-column.
2. The left and top pixels are 1. The middle would be (columns/2, rows/2). To get from the middle of the picture to pixel coordinates, you need to add half the width or height in pixels, taking special care for whether the dimension has an odd or even number of pixels in that direction.
Maura Monville
Maura Monville am 5 Apr. 2016
Thank you so much. maura

Melden Sie sich an, um zu kommentieren.


Sergey Loginov
Sergey Loginov am 5 Nov. 2021
Accumarray function allows to build both radial profiler (like this one: https://www.mathworks.com/matlabcentral/fileexchange/101480-very-fast-radial-profile) or an azimutal profiler as well.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by