@Kristian: If your RGB image comes from the imread function, it is an M x N x 3 array. You can then apply ImToPolar or PolarToIm (whichever you're interested in) 3 times, once for each plane (R,G,B) of the image. For instance:
Thank you, this code is great, but takes a little too long for my application. After reading the thread I wrote similar code which works ~12 times faster for the PolarToIm section. It doesn't have quite the same functionality but I thought I would share it here in case others are having the same problem
function imC = Polar2Im(imP,W,method)
%Polar2Im turns a polar image (imP) into a cartesian image (imC) of width W
%method can be: '*linear', '*cubic', '*spline', or '*nearest'.
imP(isnan(imP))=0;
w = round(W/2); [M N P]= size(imP);
xy = (1:W-w); [x y] = meshgrid(xy,xy);
n = round(N/4); rr = linspace(1,w,M);
W1 = w:-1:1; PM = [2 1 3;1 2 3;2 1 3;1 2 3];
W2 = w+1:2*w; nn = [1:n; n+1:2*n; 2*n+1:3*n; 3*n+1:N;];
w1 = [W1;W2;W2;W1]; aa = linspace(0,90*pi/180,n);
w2 = [W2;W2;W1;W1]; r = sqrt(x.^2 + y.^2);
a = atan2(y,x); imC= zeros(W,W,P);
for i=1:4 %turn each quarter into a cartesian image
imC(w1(i,:),w2(i,:),:) = permute(interp2(rr,aa,imP(:,nn(i,:))',r,a,method),PM(i,:));
end
imC(isnan(imC))=0;
Is it correct to use different scaling factors for different axes? A circle in an image should transpose as a rectangle in polar image, but this makes it an ellipse. Could take the min of the scaling factors (sx,sy) for both, though, you might end leaving some portion of the image.
im2polar : this update will save you 1 order of magnitude of processing time, by vectorizing the code, and using interp2 (can even do better with mex file ba_interp in file exchange) :
Watch out, this might be the transpose of the original output.
rMin=0;
rMax=1;
[Mr Nr] = size(imR); % size of rectangular image
xRc = (Mr+1)/2; % co-ordinates of the center of the image
yRc = (Nr+1)/2;
sx = (Mr-1)/2; % scale factors
sy = (Nr-1)/2;
imP = zeros(M, N);
dr = (rMax - rMin)/(M-1);
dth = 2*pi/N;
% loop in radius and
r=rMin:dr:rMin+(M-1)*dr;
th=(0:dth:(N-1)*dth)';
[r,th]=meshgrid(r,th);
x=r.*cos(th);
y=r.*sin(th);
xR = x*sx + xRc;
yR = y*sy + yRc;
imP = interp2(imR, xR, yR); %interpolate (imR, xR, yR);