matlab 图像的几何变换

图像如果向前映射有效率低,不完成等缺点,所以一般我们使用向后映射。

(1)平移:

I = imread('apostles.jpg');
I = double(I);
B = zeros(size(I));
H = size(I);
move_x = 100;
move_y = 150;
B(move_y + 1:H(1), move_x+1:H(2), 1:H(3))=...
I(1:H(1)-move_y, 1:H(2) - move_x, 1:H(3));
subplot(1,2,1),subimage(uint8(I))
title('原图像')
subplot(1,2,2),subimage(uint8(B))
title('平移变换');
I = imread('apostles.jpg');
se=translate(strel(1),[150 100]);
B = imdilate(I,se);
figure;
subplot(1,2,1),subimage(I);
title('原图像');
subplot(1,2,2),subimage(B);
title('平移变换');

(2)镜像:

I = imread('apostles.jpg');
[height, width, dim]=size(I);
%水平镜像变换
tform = maketform('affine',[-1 0 0;0 1 0; width 0 1]);
B=imtransform(I, tform, 'nearest');
%垂直镜像变换
tform2 = maketform('affine', [1 0 0; 0 -1 0; 0 height 1]);
C=imtransform(I, tform2, 'nearest');
subplot(1,3,1),imshow(I);
title('原图像');
subplot(1,3,2),imshow(B);
title('水平图像');
subplot(1,3,3),imshow(C);
title('垂直图像');
A = imread('apostles.jpg');
A = double(A);
figure(1), imshow(uint8(A));
H = size(A);
figure(2),B(1:H(1),1:H(2),1:H(3))=A(H(1):-1:1,1:H(2),1:H(3));%垂直镜像
imshow(uint8(B));
figure(3),C(1:H(1),1:H(2),1:H(3))=A(1:H(1),H(2):-1:1,1:H(3));%水平镜像
imshow(uint8(C));

(3)转置:

I = imread('apostles.jpg');
tform = maketform('affine',[0 1 0; 1 0 0; 0 0 1]);%定义转置矩阵
B = imtransform(I, tform, 'nearest');
subplot(1,2,1),imshow(I)
title('原图像');
subplot(1,2,2),imshow(B)
title('转置图像');

(4)缩放:

I = imread('C:\apostles.jpg');
A = imresize(I, 1.5, 'nearest');%最近插值法
B = imresize(I, 1.5, 'bilinear');%双线性插值法
C = imresize(I, 1.5, 'bicubic');%二次立方插值法
subplot(2,2,1), imshow(I), title('original');
subplot(2,2,2), imshow(A), title('nearest');
subplot(2,2,3), imshow(B), title('bilinear');
subplot(2,2,4), imshow(C), title('bicubic');
A = imresize(I, [a b], 'nearest');%不同方向比例差值

(5)旋转:

I = imread('apostles.jpg');
A = imrotate(I, 30, 'nearest');%旋转30度,最邻近插值
figure(1),imshow(A)
B = imrotate(I, 45, 'bilinear','loose');%旋转45度,二次线性插值
figure(2),imshow(B)
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值