用matlab实现图像的空间变换主要应用imtransform()和maketform()函数相结合
以放射性变换为例:
原图像f(x,y)变换后为g(x',y')则满足下式:
(x',y') = T(x,y)
x' = a(0)x+a(1)y+a(2)
y' = b(0)x+b(1)y+b(2)
写成矩阵则为:
[x' y' 1]' = [a(0) a(1) a(2);b(0) b(1) b(2);0 0 1][x y 1]'
代码如下:
% 图像的空间变换
[I,map] = imread('a.jpg'); %读入图片
%图像的旋转
Ta = maketform('affine',...
[cosd(30) -sind(30) 0;sind(30) cosd(30) 0; 0 0 1]'); %创建旋转结构体
Ia = imtransform(I,Ta);
%图像的放缩
Tb = maketform('affine',[5 0 0;0 10.5 0;0 0 1]); %创建放缩结构体
Ib = imtransform(I,Tb);
%图像的平移
xform = [1 0 55;0 1 115;0 0 1]';
Tc = maketform('affine',xform); %创建平移结构体
Ic = imtransform(I,Tc,'XData',...
[1 (size(I,2)+xform(3,1))],'YData',...
[1 (size(I,2)+xform(3,1))],'FillValues',255 );
%图像的整体切变
Td = maketform('affine',[1 4 0;2 1 0;0 0 1]');
Id = imtransform(I,Td,'FillValues',255);
figure,
subplot(121),imshow(Ia),axis on;
subplot(122),imshow(Ib),axis on;
figure,
subplot(121),imshow(Ic),axis on;
subplot(122),imshow(Id),axis on;