【问题标题】:Converting code to take RGB image instead of grayscale转换代码以获取 RGB 图像而不是灰度图像
【发布时间】:2014-04-23 21:17:19
【问题描述】:

我有此代码将鱼眼图像转换为矩形,但该代码只能对灰度图像执行此操作。任何人都可以帮助转换代码以对 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

【问题讨论】:

    标签: matlab rgb interpolation grayscale fisheye


    【解决方案1】:

    尝试更改这三行:

    [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
    

    【讨论】:

    • 感谢您的回答,很遗憾它不起作用。运行代码时,我收到以下错误消息:下标分配维度不匹配。 ImToPolar 中的错误(第 40 行) imP(:,:,dim) = interp2(imR(:,:,dim), xR, yR); % 插值 (imR, xR, yR);
    • 我已更新,代码现在会生成彩色输出,但插值函数似乎无法正常工作。图像不是应有的样子。
    • 您能否提供一个示例彩色图像,其中包含您使用并用于灰度的参数?
    • 好的,我会在上面添加一个链接:)
    • 我已经解决了这个问题(上面的代码现在可以工作了)谢谢你的帮助:)
    猜你喜欢
    • 1970-01-01
    • 2014-02-26
    • 2014-12-22
    • 2020-05-04
    • 2019-11-14
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    相关资源
    最近更新 更多