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图像的几何变换之图像平移
- Matlab图像的几何变换之图像平移
- Matlab学习20101207(图像读写和几何变换)
- matlab之原始处理图像几何变换
- matlab 图像几何变换 平移、旋转、缩放
- Matlab图像的几何变换之图像镜像
- matlab之原始处理图像几何变换
- Matlab图像的几何变换之图像镜像
- Matlab图像的几何变换之图像转置
- Matlab图像的几何变换之图像转置
- 在Matlab中实现图像的几何变换
- matlab之原始处理图像几何变换
- 【图像处理】MATLAB:几何变换与图像配准
- Matlab图像的几何变换之图像缩放
- Matlab图像几何变换之图像旋转
- Matlab图像的几何变换之图像缩放
- Matlab图像几何变换之图像旋转
- matlab 图像几何变换 平移、旋转、缩放
- matlab 图像的几何变换
- Matlab读取和显示图像