转换代码以获取RGB图像而不是灰度

时间:2014-04-23 21:17:20

标签: matlab rgb interpolation grayscale fisheye

我有这个代码将鱼眼图像转换成矩形,但代码只能在灰度图像上执行此操作。任何人都可以帮助转换代码以对RGB图像执行操作。代码如下:

编辑:我已更新代码以包含在每个颜色通道中执行插值的功能。但这似乎会破坏输出图像。见下面的图片

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

解决

Input image< - 图片链接

Grayscale output, what i would like in color< - 图片链接

1 个答案:

答案 0 :(得分:0)

尝试更改这三行:

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

......对于这些:

[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