3.5

3.5 | 2 ratings Rate this file 11 Downloads (last 30 days) File Size: 3.47 KB File ID: #18102
image thumbnail

Radial Scan

by Narupon Chattrapiban

 

22 Dec 2007 (Updated 26 Dec 2007)

Get radial scan of a matrix

| Watch this File

File Information
Description

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

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Draw a circle.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
02 Jan 2008 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

07 Mar 2008 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

10 Nov 2010 Barry

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

12 Nov 2010 Narupon Chattrapiban

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

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

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
radial Narupon Chattrapiban 22 Oct 2008 09:40:14
scan Narupon Chattrapiban 22 Oct 2008 09:40:14
profile Narupon Chattrapiban 22 Oct 2008 09:40:14
2d Narupon Chattrapiban 22 Oct 2008 09:40:14
matrix Narupon Chattrapiban 22 Oct 2008 09:40:14
image Narupon Chattrapiban 22 Oct 2008 09:40:14
ellipse Narupon Chattrapiban 22 Oct 2008 09:40:14
circle Narupon Chattrapiban 22 Oct 2008 09:40:14
radial Elena Marchini 08 Jul 2009 11:35:23
circle Vijayakumar 06 May 2010 09:33:21
image Elier 10 Feb 2012 10:32:52
profile Elier 10 Feb 2012 11:30:04

Contact us at files@mathworks.com