matlab学习2-图像处理位移变换

图像处理,translate、imrotate、maketform、imtransform的用法
1、图像平移
效果如下:在这里插入图片描述

在这里插入图片描述

test.m代码如下:

% 图像平移
img1=imread("img.jpg");

% translate(SE,[y,x])在结构元素SE上进行y和x方向的位移,正数对应右移
se=translate(strel(1),[100 80]);
se1=translate(strel(1),[-100 -80]);
img2=imdilate(img1,se);%形态学膨胀
img3=imdilate(img1,se1);%形态学膨胀
figure;
subplot(1,3,1),subimage(img1);
title('原图像')
subplot(1,3,2),subimage(img2);
title('图像右下平移')
subplot(1,3,3),subimage(img3);
title('图像左上平移')

2、图像放大缩小
效果如下
在这里插入图片描述

test.m代码如下:

% 图像放大
img1=imread('img.jpg');
img2=imresize(img1,0.5);
img3=imresize(img1,1.5);

% subplot(1,3,1),subimage(img1);
% subplot(1,3,2),subimage(img2);
% subplot(1,3,3),subimage(img3);
figure,imshow(img1),xlabel('(a)原图像');
figure,imshow(img2),xlabel('(b)缩小后图像');
figure,imshow(img3),xlabel('(c)放大后图像');

3、图像旋转
效果如下
在这里插入图片描述

test.m代码如下:

%图像旋转,顺时针和逆时针旋转
img1=imread('img.jpg');
img2=imrotate(img1,30,'nearest','crop');
img3=imrotate(img1,30,'nearest');
%显示
subplot(1,3,1);imshow(img1);title("原图");
subplot(1,3,2);imshow(img2);title("原图旋转30");
subplot(1,3,3);imshow(img3);title("自适应旋转30");

4、图像旋转方法二
效果如下
在这里插入图片描述

test.m代码如下:

%图像旋转,顺时针和逆时针旋转
img1=imread('img.jpg');
tform=maketform("affine",[0 1 0;1 0 0;0 0 1]);
img2=imtransform(img1,tform,"nearest");

subplot(1,2,1);imshow(img1);title("原图");
subplot(1,2,2);imshow(img2);title("转置图");

素材代码:
gitee:https://gitee.com/CYFreud/matlab/tree/master/image_processing/demo2

猜你喜欢

转载自blog.csdn.net/CHengYuP/article/details/123785216