Why does this bilinear interpolation algorithm have two Y(i,j) outputs (i.e. Y(i,j)=I(c​eil(y),cei​l(x)) and Y(i,j)=(y-y2)*P+(y1-y)*Q )? How difference are they ?

3 次查看(过去 30 天)
What is the meaning of each bolded-lines in the traditional bilinear interpolation algorithm source code shown below ? Why these TWO 'outputs' and HOW different are they ? Can you please explain with an illustration, if possible ?
----------------------------------- clc close all clear all I=imread('LENNA64.bmp'); [originheight,originwidth]=size(I); height=4*originheight; width=4*originwidth;
Y=zeros(height,width);
[height,width]=size(Y); hscale=originheight/height; wscale=originwidth/width;
for i=1:height y=hscale*i; for j=1:width x=wscale*j;
if(floor(x)==0)||(floor(y)==0)||(ceil(x)==originwidth)||(ceil(y)==originheight)
*Y(i,j)=I(ceil(y),ceil(x));*
else
x1=floor(x);
x2=x1+1;
y2=floor(y);
y1=y2+1;
N1=I(y2,x1);
N2=I(y2,x2);
N3=I(y1,x2);
N4=I(y1,x1);
Q=(x2-x)*(N1)+(x-x1)*(N2);
P=(x2-x)*(N4)+(x-x1)*(N3);
*Y(i,j)=(y-y2)*P+(y1-y)*Q;*
end
end
end
Y=uint8(Y); figure;imshow(Y);

采纳的回答

Geoff Hayes
Geoff Hayes 2014-10-10
OL - look closely at the if condition
(floor(x)==0)||(floor(y)==0)||(ceil(x)==originwidth)||(ceil(y)==originheight)
As x and y are converted to integers via either floor or ceil, then the former may set x or y to zero, and the latter may set the x and y to an the number of rows (height) or columns (width) in the image.
If either x or y are zero, then those are invalid indices into the image matrix, so the lines (in the else block) would fail. If either are identical to the number or rows or columns in the matrix, then adding one to either of these indices (as is done in the else block) would create an index that exceeds the dimension of the matrix and so would fail.
Basically, the if block is a guard against the code trying to make use of neighbouring pixels that fall outside of the image. In the interpolated image, the pixels along its edges are identical to those from the original image (because of the if block), and it is only those pixels within that are determined using the bilinear interpolation algorithm (see the else block).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by