1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
function [img2,e,n]=logpolar(img)
% LOGPOLAR Transform image from Cartesian to Log-Polar coordinates
% IMG2 = LOGPOLAR(IMG) transforms the Cartesian image IMG to
% Log-Polar image IMG2.
% [IMG2,E,N] = LOGPOLAR(IMG) exports the interpolation data grid.
% E : radius data
% N : angle data
%
% Author: Jérôme Briot
% http://www.developpez.net/forums/member.php?u=125006
% http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094934&objectType=author
% Contact: dutmatlab@remove@yahoo.fr
% Version: 1.0 - 26 Feb 2008
% Comments:
%
error(nargchk(1,1,nargin));
cl=class(img);
[r,c]=meshgrid(1:size(img,2),1:size(img,1));
r=r-size(img,2)/2;
c=c-size(img,1)/2;
R=logspace(0,log10(floor(max([size(img,1) size(img,2)])/2)),64);
th=linspace(0,2*pi,150);
e=R.'*cos(th);
n=R.'*sin(th);
if ndims(img)==3
R = interp2(r,c,double(img(:,:,1)),e,n);
G = interp2(r,c,double(img(:,:,2)),e,n);
B = interp2(r,c,double(img(:,:,3)),e,n);
img2 = cat(3,R,G,B);
else
img2=interp2(r,c,double(img),e,n,'linear');
end
img2 = cast(img2,cl);
if nargin==3
e=e+size(img,1)/2;
n=n+size(img,2)/2;
end |
Partager