图像镜像又分为水平镜像和竖直镜像。水平镜像即将图像左半部分和右半部分以图像竖直中轴线为中心轴进行兑换;而数值镜像则是将图像上半部分和下半部分以图像水平中轴线为中心轴进行对换。
imtransform()函数用于完成一般的二维空间变换,形式如下。
B=imtransform(A,TFORM,method);
参数A为要进行几何变换的图像
空间变换结构TFORM指定了具体的变换类型
可选参数method允许为imtransform()函数选择的差值方法
fourth4_3
%镜像变换
A=imread('pout.tif');
[height,width,dim]=size(A);
tform=maketform('affine',[-1 0 0;0 1 0;width 0 1]);
%定义水平镜像变换矩阵
B=imtransform(A,tform,'nearest');
tform2=maketform('affine',[1 0 0;0 -1 0;0 height 1]);
%定义竖直变换矩阵
C=imtransform(A,tform2,'nearest');
subplot(1,3,1);imshow(A);title('原图像');
subplot(1,3,2);imshow(B);title('水平镜像');
subplot(1,3,3);imshow(C);title('竖直镜像');