【发布时间】:2015-04-03 01:26:00
【问题描述】:
在这里,我想使用双线性插值法放大我的图像(灰色),但我无法正确生成最终输出图像,这是 matlab 代码:
I = imread('house.png'); %image i want to zoom in
fact = 1.5;
[rows,cols] = size(I);
Jrows = fact * rows;
Jcols = fact * cols;
J = zeros(floor(fact * size(I)));
I = [I(1,:);I];
I = [I;I(end,:)]; %replicating boundaries.
I = [I(:,1) ,I];
I = [I,I(:,end)];
I = double(I);
for i = 2: Jrows-2
for j = 2: Jcols-2
x1 = floor(i/fact);
x2 = ceil(i/fact);
y1 = floor(j/fact); %finding neighbours
y2 = ceil(j/fact);
if x1==0
x1=1;
end
if y1==0
y1=1;
end
J(i-1,j-1) = (I(x1,y1)*(x2-i)*(y2-j) + I(x2,y1)*(i-x1)*(y2-j)+ I(x1,y2)*(x2-i)*(j-y1) + I(x2,y2)*(i-x1)*(j-y1));
end
end
figure,imshow(uint8(J)),title('zoom in image'); #final image
在这段代码中,我得到了缩放图像,但我丢失了一些像素值,并且没有得到正确的图像。
【问题讨论】:
-
我引用您的链接不是精确重复的,但您需要先使用双线性插值调整图像大小。然后,当您完成后,只需裁剪您想要的图像的任何部分,这将构成您的缩放图像。在缩放后的图像中选择一个您想要的中心像素,并提取出与原始图像尺寸相同的像素。
标签: matlab zooming interpolation