先使用matlab自带的函数imresize
pic=imread('data/2.jpg'); J=imresize(pic,2,'nearest'); K=imresize(pic,2,'bilinear'); L=imresize(pic,2,'bicubic'); figure(1); imshow(pic); figure(2); imshow(J); figure(3); imshow(K); figure(4); imshow(L);
近邻插值法:
是最简单暴力的算法,时间最短效果最差。
放大1.5倍代码
pic=imread('data/2.jpg'); [x,y,z]=size(pic); x=round(x*1.5); y=round(y*1.5); new_pic=zeros(x,y,z,class(pic)); for i=1:x for j=1:y for k=1:z a=round(i/1.5); b=round(j/1.5); new_pic(i,j,k)=pic(a,b,k); end end end figure; imshow(pic); title("Original picture"); figure; imshow(new_pic); title("Nearest neighbor");
双线性插值法:
代码在原图像补全的部分有问题。后续补上。