图像变换——等距变换、相似变换、仿射变换、投影变换

%%图像变换
% I = imread('cameraman.tif');
I = imread('F:\stitching\imagess\or\baiyun2.jpg');
figure; imshow(I); title('原始图像');
[w,h]=size(I);
theta=pi/4;%旋转角
t=[200,80];%平移tx,ty
s=0.3;%缩放尺度
%% 等距变换=平移变换+旋转变换
H_e=projective2d([cos(theta) sin(theta) t(1);
              -sin(theta)  cos(theta) t(2);
                  0           0       1]');
I_e=imwarp(I,H_e);
figure; imshow(I_e); title('等距变换');
%% 相似变换=等距变换+均匀缩放
H_s=projective2d([s*cos(theta) -s*sin(theta) t(1);
                  s*sin(theta)  s*cos(theta) t(2);
                     0           0       1]');
I_s=imwarp(I,H_s);
figure; imshow(I_s); title('相似变换');
%% 仿射变换=平移变换+非均匀变换
H_a=projective2d([1 0.2 t(1);
                 0 1 t(2);
                 0 0  1]');
I_a=imwarp(I,H_a);
figure; imshow(I_a); title('仿射变换');
%% 投影变换
H_P=projective2d([0.765,-0.122,-0.0002;
                 -0.174,0.916,9.050e-05;
                  105.018,123.780,1]);
I_P=imwarp(I,H_P);
figure; imshow(I_P); title('投影变换');

% %% 黑色背景变白色
% linear_out = I_a;
% redChannel = linear_out(:, :, 1);
% greenChannel = linear_out(:, :, 2);
% blueChannel = linear_out(:, :, 3);
% thresholdValue = 0;
% mask = redChannel == thresholdValue & greenChannel == thresholdValue & blueChannel == thresholdValue;
% maskedRed = redChannel;
% maskedGreen = greenChannel;
% maskedBlue = blueChannel;
% % Do the masking - make white where it was black.
% maskedRed(mask) = 255;
% maskedGreen(mask) = 255;
% maskedBlue(mask) = 255;
% mosaic = cat(3, maskedRed, maskedGreen, maskedBlue);
% figure; imshow(mosaic);

 实验结果:

等距变换:

相似变换

仿射变换

投影变换

参考文章图像变换——等距变换,相似变换,仿射变换,投影变换_投影扭曲 相似扭曲-CSDN博客

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值