function result=imagezoom(I,r,mode) %ImageZoom writen by WenjingHu %Input: I the image to be zoom %Output: result the image zoomed if (ndims(I)~=2)
error('the input I must be an image of two dimensional!'); end
if (r<=0)
error('the ratio r must be >=0'); end
[m n]=size(I);
result=zeros(round(m*r),round(n*r)); for i=ceil(2*r):m*r-2*r for j=ceil(2*r):n*r-2*r switch (mode) case 'NNI'
result(i,j)=I(ceil(i/r),ceil(j/r)); case 'BL'
u=i/r-floor(i/r);v=j/r-floor(j/r);
result(i,j)=(1-u)*(1-v)*I(floor(i/r),floor(j/r)) + (1-u)*v*I(floor(i/r),floor(j/r)+1) + u*(1-v)*I(floor(i/r)+1,floor(j/r)) + u*v*I(floor(i/r)+1,floor(j/r)+1); case 'BC'
u=i/r-floor(i/r);v=j/r-floor(j/r);
A=[ S(u + 1) S(u + 0) S(u - 1) S(u - 2) ];
B=[I(floor(i/r)-1, floor(j/r)-1) I(floor(i/r)-1, floor(j/r)+0) floor(j/r)+1) I(floor(i/r)-1, floor(j/r)+2);
I(floor(i/r)+0, floor(j/r)-1) I(floor(i/r)+0, I(floor(i/r)+0, floor(j/r)+1) I(floor(i/r)+0, floor(j/r)+2); I(floor(i/r)+1, floor(j/r)-1) I(floor(i/r)+1, I(floor(i/r)+1, floor(j/r)+1) I(floor(i/r)+1, floor(j/r)+2); I(floor(i/r)+2, floor(j/r)-1) I(floor(i/r)+2,
I(floor(i/r)+2, floor(j/r)+1) I(floor(i/r)+2, floor(j/r)+2)]; C=[S(v+1) S(v+0) S(v-1) S(v-2)]'; result(i,j)=A*double(B)*C; end end end
function s=S(x) fabs=abs(x);
I(floor(i/r)-1, floor(j/r)+0) floor(j/r)+0) floor(j/r)+0)
if (fabs>=0 && fabs<1) s=1-2*fabs^2+fabs^3; elseif (fabs>=1 && fabs<2)
s=4-8*fabs+5*fabs^2-fabs^3; else
s=0; end
因篇幅问题不能全部显示,请点此查看更多更全内容