仿射变换和逻辑变换
1、尺度变换
示例:对图像进行尺度变换
编写对应的m文件如下:
clear all;
I=checkerboard(30,6);
subplot(1,2,1)
imshow(I);
title('原始图像');
s=1.5;
T=[s 0;0 s;0 0];
K=maketform('affine',T);
I1=imtransform(I,K,'bicubic','FillValues',0.9);
subplot(1,2,2)
imshow(I1);
title('尺寸变换图像');
程序运行结果如下图:
2、伸缩变换,对图像实现伸或缩运算
示例:对图像进行伸缩变换
编写对应的m文件如下:
clear all;
I=checkerboard(30,6);
subplot(1,2,1)
imshow(I);
title('原始图像');
t=3;
T=[1 0;0 t;0 0];
K=maketform('affine',T);
I1=imtransform(I,K,'bicubic','FillValues',0.9);
subplot(1,2,2)
imshow(I1);
title('伸缩变换图像');
程序运行如下图:
3、扭曲变换
示例:对图像进行扭曲变换
编写对应的m文件如下:
clear all;
I=checkerboard(30,6);
subplot(1,2,1)
imshow(I);
title('原始图像');
u=0.8;
T=[1 u;0 1;0 0];
K=maketform('affine',T);
I1=imtransform(I,K,'bicubic','FillValues',0.9);
subplot(1,2,2)
imshow(I1);
title('扭曲变换图像');
程序运行结果如下图:
4、旋转变换
示例:对图像进行旋转变换
编写对应m文件如下:
clear all;
I=checkerboard(30,6);
subplot(1,2,1)
imshow(I);
title('原始图像');
theta=pi/3;
T=[cos(theta) -sin(theta);sin(theta) cos(theta);0 0];
K=maketform('affine',T);
I1=imtransform(I,K,'bicubic','FillValues',0.9);
subplot(1,2,2)
imshow(I1);
title('旋转变换图像');
程序运行结果如下图:
5、图像的逻辑运算位与运算,bitand函数用于实现图像的位与运算
示例:利用bitand函数进行图像位与运算
编写对应的m文件如下:
clear all;
I=imread('peppers.png');
subplot(1,3,1)
imshow(I);
title('原始图像');
I1=imdivide(I,3);
subplot(1,3,2)
imshow(I1);
title('相除后图像');
I2=bitand(I,I1);
subplot(1,3,3)
imshow(I2);
title('位与运算图像');
运行程序结果如下图:
6、图像的逻辑运算位补运算,bitcmp函数用于实现图像的位补运算
示例:对图像进行求补运算
clear all;
I=imread('trees.tif');
subplot(1,2,1)
imshow(I);
title('原始图像');
I1=bitcmp(I,8);
subplot(1,2,2)
imshow(I1);
title('位补运算图像');
程序运行结果如下图:
7、图像的逻辑运算位或运算,bitor函数用于实现图像的位或运算
示例:对图像进行位或运算
编写对应m文件如下:
clear all;
I=imread('peppers.png');
subplot(1,3,1)
imshow(I);
title('原始图像');
I1=imdivide(I,3);
subplot(1,3,2)
imshow(I1);
title('相除后图像');
I2=bitor(I,I1);
subplot(1,3,3)
imshow(I2);
title('位或运算图像');
程序运行结果如下图:
8、图像的逻辑运算位异或运算和位移位运算,bixor函数用于实现图像的位异或运算,bitshift函数用于实现图像位移位运算
示例:实现图线位移位运算
编写对应m文件如下:
clear all;
I=imread('trees.tif');
subplot(1,2,1)
imshow(I);
title('原始图像');
I1=bitshift(I,3);
subplot(1,2,2)
imshow(I1);
title('位移位运算图像');
程序运行结果如下图: