您的位置:首页 > 编程语言 > MATLAB

matlab 图像的几何变换

2016-11-21 23:09 323 查看

1 启动MATLAB程序,读入图像并对图像文件分别进行平移、垂直镜像变换、水平镜像变换、缩放和旋转操作

%%%%%%平移
>> flowerImg=imread('flower.jpg');
>> se=translate(strel(1),[100 100]);
>> img2=imdilate(flowerImg,se);
>> subplot(1,2,1);
>> imshow(flowerImg);
>> subplot(1,2,2);
>> imshow(img2);
I1=imread('flower.jpg');
I1=double(I1);
H=size(I1);
I2(1:H(1),1:H(2),1:H(3))=I1(H(1):-1:1,1:H(2),1:H(3));
I3(1:H(1),1:H(2),1:H(3))=I1(1:H(1),H(2):-1:1,1:H(3));
Subplot(2,2,1);
Imshow(uint8(I1));
Title('原图');
Subplot(2,2,2);
Imshow(uint8(I3));
Title('水平镜像');
Subplot(2,2,3);
Imshow(uint8(I2));
Title('垂直镜像');


img1=imread('flower.jpg');
figure,imshow(img1);
%%%%%%缩放
img2=imresize(img1,0.25);
figure,imshow(img2);
imwrite(img2,'a2.jpg');
%%%%%%旋转
img3=imrotate(img1,90);
figure,imshow(img3);
imwrite(img3,'a3.jpg');


2 实验如下操作:

(1) 改变图像缩放比例

f= imread('flower.jpg');

T=[ 0.5 0 0; 0 0.5 0; 0 0 1];
tform=maketform('affine',T);
[g1,xdata1,ydata1]=imtransform(f,tform,'FillValue',255);

T=[ 1 0 0; 0 1 0; 0 0 1];
tform=maketform('affine',T);
[g2,xdata2,ydata2]=imtransform(f,tform,'FillValue',255);

T=[ 1.5 0 0; 0 1.5 0; 0 0 1];
tform=maketform('affine',T);
[g3,xdata3,ydata3]=imtransform(f,tform,'FillValue',255);

hold on
imshow(g3,'XData', xdata3, 'YData', ydata3)

hold on
imshow(g2,'XData', xdata2, 'YData', ydata2)

hold on
imshow(g1,'XData', xdata1, 'YData', ydata1)

axis auto
axis on


(2) 改变图像的旋转角度,

f= imread('flower.jpg');

theta=3*pi/4;
T=[cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1];
tform=maketform('affine',T);
[g3,xdata3,ydata3]=imtransform(f,tform,'FillValue',255);

theta=pi;
T=[cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1];
tform=maketform('affine',T);
[g4,
4000
xdata4,ydata4]=imtransform(f,tform,'FillValue',255);

imshow(f);

hold on
imshow(g3,'XData', xdata3, 'YData', ydata3)

hold on
imshow(g4,'XData', xdata4, 'YData', ydata4)

axis auto
axis on
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  matlab 图像 几何变换