bilinear_interpolation_shrink.m

来自「MATLAB双线性插值法对图像进行放大和缩小」· M 代码 · 共 40 行

M
40
字号
function Bilinear_Interpolation_Shrink
f1024=imread('1024.jpg');
[imagewidth,imageheight]=size(f1024);
width=256;
height=256;
f256=uint8(zeros(width,height));
wscale=imagewidth/width;
hscale=imageheight/height;

for i=1:width   
for j=1:height      
x=i*wscale;      
y=j*hscale;

if(x==floor(x)) & (y==floor(y)) 
f256(i,j)=f1024(int16(x),int16(y)); 
       
else 
if(floor(x)==0) | (floor(y)==0) 
f256(i,j)=f1024(1,1);

else 
x11=double(f1024(floor(x),floor(y)));      
x12=double(f1024(floor(x),ceil(y)));      
x21=double(f1024(ceil(x),floor(y)));      
x22=double(f1024(ceil(x),ceil(y)));            
Wx1=1-(x-floor(x));      
Wx2=x-floor(x);      
Wy1=1-(y-floor(y));      
Wy2=y-floor(y);            

f256(i,j)=[Wx1 Wx2]*[x11 x12;x21 x22]*[Wy1;Wy2];  
end
end
end
end

figure('Name','The 1024 x 1024 picture','NumberTitle','off'),imshow(f1024)
figure('Name','The 256 x 256 picture','NumberTitle','off'),imshow(f256)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?