图像的放大与缩小(MATLAB 代码)

首先第一种:

function I=ImageZoom(I1,x,y)
%功能:实现图像的任意倍数缩放
%x---水平缩放系数
%y---竖直缩放系数

if length(size(I1))>2
I1=rgb2gray(I1);
end

figure,imshow(I1);
[m,n]=size(I1);

newWidth=round(x*m);
newHeight=round(x*n);

T=[x 0 0;0 y 0;0 0 1];
tform=maketform('affine',T);

tx=zeros(newWidth,newHeight);
ty=zeros(newWidth,newHeight);
for i=1:newWidth
for j=1:newHeight
tx(i,j)=i;
ty(i,j)=j;
end
end

[w z]=tforminv(tform,tx,ty); %反向坐标值

I=uint8(zeros(newWidth,newHeight));

%给新图像各像素点赋值
for i=1:newWidth
for j=1:newHeight
S_x=w(i,j);
S_y=z(i,j);
if(S_x>=m-1||S_y>=n-1||double(uint16(S_x))<=0||double(uint16(S_y))<=0)
I(i,j)=0; %不在原图像上
else
if (S_x/double(uint16(S_x))==1.0&a


版权声明:本文为u013146742原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。