function G=chazhi2(im1,u,v) %双线性插值计算灰度值
G=zeros(256,256);
for x=1:256
for y=1:256
xx = x+u(x,y);
yy = y+v(x,y);
if (xx/double(uint8(xx)) == 1.0) &(yy/double(uint8(yy)) == 1.0)
G(x,y) = im1(uint8(xx),uint8(yy));
else if (xx<1.0)|(yy<1.0)|(xx>=255)|(yy>=255)
G(x,y)=im1(x,y);
else % a or b is not integer
a = double(uint8(xx));
b = double(uint8(yy));
x11 = double(im1(a,b)); % x11 <- T(a,b)
x12 = double(im1(a,b+1)); % x12 <- T(a,b+1)
x21 = double(im1(a+1,b)); % x21 <- T(a+1,b)
x22 = double(im1(a+1,b+1)); % x22 <- T(a+1,b+1)
G(x,y) = uint8( (b+1-yy) * ((xx-a)*x21 + (a+1-xx)*x11) + (yy-b) * ((xx-a)*x22 +(a+1-xx) * x12) ); % calculate G(x,y)
end
end
end
end
- 1
- 2
前往页