我有一些代码可以获取鱼眼图像并将其转换为每个 RGB 通道中的矩形图像。我遇到了输出图像是正方形而不是矩形的问题。(这意味着图像失真,水平压缩。)我尝试将输出矩阵更改为更合适的格式,但没有成功。除此之外,我还发现要使代码正常工作,输入图像必须是 500x500 的正方形。知道如何解决这个问题吗?这是代码:
该代码的灵感来自 Mathworks 上的 Prakash Manandhar “图像的极坐标到/从矩形变换”文件交换。
编辑。代码现在可以工作了。
function imP = FISHCOLOR2(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;
reduced_dim = min(size(imR,1),size(imR,2));
imR = imresize(imR,[reduced_dim reduced_dim]);
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;
for k=1:Dr % colors
imP(:,:,k) = interp2(imR(:,:,k), xR, yR); % add k channel
end
imP = imresize(imP,[size(imP,1), size(imP,2)/3]);
imP = imrotate(imP,270);
解决了
输入图片<- 图片链接
输出图像<- 图像链接