Question

I have this code converting a fisheye image into rectangular form but the code is only able to perform this operation on a grayscale image. Can anybody help converting the code to perform the operation on a RGB image. The code is as follows:

edit: I have updated the code to contain a functionality which performs interpolation in each color channel. But this seem to disform the output image. See pictures below

function imP = FISHCOLOR (imR)

rMin=0.1; 
rMax=1;

[Mr, Nr, Dr] = 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;

M=size(imR,1);N=size(imR,2);


dr = (rMax - rMin)/(M-1); 
dth = 2*pi/N;

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 =zeros(M, N);              % initialize the final matrix
 for k=1:3 % colors
    T = imR(:,:,k);
     Ichannel = interp2(T,xR,yR);
     imP(:,:,k)= Ichannel;          % add k channel
 end

SOLVED

Input image <- Image link

Grayscale output, what i would like in color <- Image link

Was it helpful?

Solution

Try changing these three lines:

[Mr Nr] = size(imR); % size of rectangular image
...
imP = zeros(M, N);
...
imP = interp2(imR, xR, yR); %interpolate (imR, xR, yR);

...to these:

[Mr Nr Pr] = size(imR); % size of rectangular image
...
imP = zeros(M, N, Pr);
...
for dim = 1:Pr
    imP(:,:,dim) = interp2(imR(:,:,dim), xR, yR); %interpolate (imR, xR, yR);
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top