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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| function [img2,e,n]=logpolar(img,interpolation)
% 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
% [...] = LOGPOLAR(IMG,INTERPOLATION) specifies the interpolation method:
%
% 'nearest' Nearest neighbor interpolation
% 'linear' Linear interpolation (default)
% 'spline' Cubic spline interpolation
% 'cubic' Cubic interpolation, as long as data is
% uniformly-spaced. Otherwise, this method is the
% same as 'spline'.
%
% 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
% 1.1 - 27 Feb 2008 Interpolation method switch added.
% Comments:
%
error(nargchk(1,2,nargin));
if nargin == 1
interpolation = 'linear';
else
if ~any(strcmp(interpolation,{'nearest' 'linear' 'spline' 'cubic' }))
error('Wrong interpolation method : %s',interpolation)
end
end
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(sqrt(2)*max([size(img,1) size(img,2)])/2)),104);
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,interpolation);
G = interp2(r,c,double(img(:,:,2)),e,n,interpolation);
B = interp2(r,c,double(img(:,:,3)),e,n,interpolation);
img2 = cat(3,R,G,B);
else
img2=interp2(r,c,double(img),e,n,interpolation);
end
img2 = cast(img2,cl);
if nargin==3
e=e+size(img,1)/2;
n=n+size(img,2)/2;
end |
Partager