<span style="font-family:宋体;font-size:14px;">
</span><p style="margin: 0cm 0cm 0pt;"><span style="font-size:14px;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">一直在用</span><span style="font-family:Calibri;"><span lang="EN-US">MATLAB</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的各种函数来实现对图像的仿射变换,比如旋转,平移、放大、缩小</span></span></p><span style="font-family:宋体;font-size:14px;">
</span><p style="margin: 0cm 0cm 0pt;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-size:14px;">可是不知道是怎么实现的。</span></span></p><span style="font-family:宋体;font-size:14px;">
</span><p style="margin: 0cm 0cm 0pt;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-size:14px;">看了一下图像的书,自己根据那些公式写了一些代码实现了对图像的变换</span></span></p><span style="font-family:宋体;font-size:14px;">
</span>
clc
f=imread('lena.jpg');
f=rgb2gray(f);
[row,col]=size(f);
T=[1 1.5 0;
1.5 1 0;
0 0 1]; %变换矩阵
tform=maketform('affine',T); %获得仿射变换结构体
[B,xdata,ydata]=imtransform(f,tform);%对图像进行变换
imshow(B)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%一下为自己实现的仿射变换,不过没有实现插值
%%%%%%%%%%%%%%%%%%%%%%%%
k=1;
tempxy=zeros(3,16*16);
for x=1:row
for y=1:col
tempxy(:,k)=T*[x;y;1];%对坐标进行变换
k=k+1;
end
end
nsize=T*[row,col,1]';
tempxy=round(tempxy(1:2,:));%对坐标取整
k=1;
C=zeros(nsize(1)-1,nsize(2));
for x=1:row
for y=1:col
C(tempxy(1,k)-1,tempxy(2,k))=f(x,y);%将像素值搬移到对应的位置
k=k+1;
end
end
figure
imshow(C/256)