File Exchange

image thumbnail

Radial Scan

version 1.0.0.0 (1.52 KB) by Narupon Chattrapiban
Get radial scan of a matrix

1 Download

Updated 26 Dec 2007

No License

Get radial scan of a matrix using the following procedure:
[1] Get coordinates of a circle around an origin.
[2] Average values of points where the circle passes through.
[3] Change radius of the circle and repeat [1] until rprofile is obtained.

% For DEMO, run
% >> rscan_qavg();
% or
% >> rscan_qavg('demo','dispflag',0);
% >> plot(ans);
% or
% >> rdat = rscan_qavg();
% >> plot(rdat);
% or
% >> a = peaks(300);
% >> rscan_qavg(a);
% >> rscan_qavg(a,'rlim',50,'xavg',100);
% >> rscan_qavg(a,'rlim',25,'xavg',100,'dispflag',1,'dispflagc',1);
% >> rscan_qavg(a,'rlim',25,'xavg',100,'dispflag',1,'dispflagc',1, ...
% 'squeezx',0.7,'rot',pi/4);
%
% Draw Circle:
% [ref] http://www.mathworks.com/matlabcentral/fileexchange/
% loadFile.do?objectId=2876&objectType=file

Cite As

Narupon Chattrapiban (2020). Radial Scan (https://www.mathworks.com/matlabcentral/fileexchange/18102-radial-scan), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Could you please provide detailed documentation?

It's hard to understand what M0 is and where to change the code so that the scan is done on another function surface.

This is a great function... for those having trouble understanding what it does it's pretty simple, here's the gist:

It takes a circle of radius r and grows it by an amount dr. Then it calculates the average value of the function between the two circles with radius r and r+dr. It continues to do this until it reaches the maximum circle size. It outputs the average value of the function inside all these circles. Great for analyzing profiles that have radial symmetry.

Thank you!

Josh

Useful program, but does anyone have documentation for it? The lack of comments and the ambiguity of variable names made it difficult to read. I love the idea, I'm just having trouble understanding how things were calculated.

sundar

I found where you do the normalization (Line 124).
I do not know why you would need this in the first place. Thanks for a very useful function.

This code should be changed a bit.
You might want to change the code in line 71 from

Rbnd = floor(min(yxz)/2)-1;

to

Rbnd = min([xavg,yxz(2)-xavg,yavg,yxz(1)-yavg])-1;

The function can be used as the following.

If you have a 250x250 matrix, M, then the radial profile
originates at (xc,yc) = (125,125) can be obtained from

r = rscan(M,'xavg',xc,'yavg',yc);

The option 'squeezx' and 'squeezy' is used to scan M with
ellipses instead of circles. You can try to change squeezx to
have a different value from squeezy and see what the program
will do. The option 'rot' is used to align the ellipses, 'rlim' is to
change the range of your scan, and 'rstep' is to change the size
of rscan increment. All the variables are described in pixels.
Finally, 'dispflag' and 'dispflagc' can be set to be either 1 or 0.
They are used to either turn the display on or off. Try and see
what they will do.

Anyhow the function rscan here is probably too slow.
You might want to consider the code 'rscan2' below.

For a matrix M, the radial profile 'P' whose coordinates is 'R'
can be obtained from

[R,P] = rscan2(M,rh,N);
figure;plot(R,P);

where 'rh' is the polar coordinates corresponding to M e.g.
x = linspace(-1,1,size(M,2));
y = linspace(-1,1,size(M,1));
[xx,yy] = meshgrid(x,y);
[th,rh]=cart2pol(xx,yy);

and 'N' is the length of R and P you want to have.

try
>> help rscan2

for more examples.

% %%%%%%%%%%%%%%%%%%%%%%%

function [rAvg,yAvg,rStd,yStd,r,y] = rscan2(Ih,rh,N)

% [rAvg,yAvg,rStd,yStd,r,y] = rscan2(Ih,rh,N)
% Ih -- 2D Matrix
% rh -- polar rho Matrix (e.g. from cart2pol)
% N -- number elements in the output radial profile
%
% Example:
%
% x = linspace(-5,5,500);
% [xx,yy] = meshgrid(x);
% [th,rh]=cart2pol(2*cos(pi/3)*xx-
2*sin(pi/3)*yy,sin(pi/3)*xx+cos(pi/3)*yy);
% figure(1);clf;imagesc(rh)
% Ih = exp(-(rh/2).^2);
% figure(2);imagesc(Ih);
% [rAvg,yAvg] = rscan2(Ih,rh,10000);
% figure(3);plot(rAvg,yAvg);
%
% [th,rh]=cart2pol(xx,yy);
% Ih = exp(-(rh/2).^2);
% figure(2);imagesc(Ih);
% [rAvg,yAvg] = rscan2(Ih,rh,10000);
% figure(3);hold on;plot(rAvg,yAvg,'r--');
%

if nargin < 3, N = numel(rh); end

if N > numel(rh), N = numel(rh); end

dPxl = floor(numel(rh)/N);
nmEL = dPxl*N; % -> prepare for reshape

[r,i] = sort(rh(:));
y = Ih(i);

% v-- strip away element that cannot be reshape
r(nmEL+1:end) = [];
y(nmEL+1:end) = [];

rAvg = mean(reshape(r,dPxl,N),1);
yAvg = mean(reshape(y,dPxl,N),1);
rStd = std(reshape(r,dPxl,N),0);
yStd = std(reshape(y,dPxl,N),0);

if nargout == 0
figurel(10);clf;hold on;box on;
plot(r,y,'g'); plot(rAvg,yAvg,'b--');
end

% %%%%%%%%%%%%%%%%%%%%%%%

Barry

Even though not easy to understand at first.... it works very well for me...excellent

saif shloul

can this code help me if i have an alpha a character i need tht to use it in hand wriiting recognation
plz send me i need your help

Amit Shachaf

The comments are not sufficient to understand what propose of the code.
It is very important to document clearly what the code is doing and what is the benefit.

Thanks - Amit

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Draw a circle.