图像处理之图像镜像

图像镜像变换公式为:
水 平 镜 像 : { x ∗ = M − 1 − x y ∗ = y 水平镜像: \left\{ \begin{matrix} x^* & = & M - 1 - x \\ y^* & = & y \end{matrix} \right. {xy==M1xy
垂 直 镜 像 : { x ∗ = x y ∗ = M − 1 − y 垂直镜像: \left\{ \begin{matrix} x^* & = & x \\ y^* & = & M - 1 -y \end{matrix} \right. {xy==xM1y
对 角 镜 像 : { x ∗ = M − 1 − x y ∗ = M − 1 − y 对角镜像: \left\{ \begin{matrix} x^* & = & M - 1 -x \\ y^* & = & M - 1 -y \end{matrix} \right. {xy==M1xM1y
用矩阵表示为:
水 平 镜 像 : { x ∗ y ∗ 1 } = { − 1 0 M − 1 0 1 0 0 0 1 } { x y 1 } 水平镜像: \left\{ \begin{matrix} x^* \\ y^* \\ 1 \end{matrix} \right\}= \left\{ \begin{matrix} -1 & 0 & M- 1 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{matrix} \right\} \left\{ \begin{matrix} x \\ y \\ 1 \end{matrix} \right\} xy1=100010M101xy1

垂 直 镜 像 : { x ∗ y ∗ 1 } = { 1 0 0 0 − 1 N − 1 0 0 1 } { x y 1 } 垂直镜像: \left\{ \begin{matrix} x^* \\ y^* \\ 1 \end{matrix} \right\}= \left\{ \begin{matrix} 1 & 0 & 0 \\ 0 & -1 & N - 1 \\ 0 & 0 & 1 \end{matrix} \right\} \left\{ \begin{matrix} x \\ y \\ 1 \end{matrix} \right\} xy1=1000100N11xy1

对 角 镜 像 : { x ∗ y ∗ 1 } = { − 1 0 M − 1 0 − 1 N − 1 0 0 1 } { x y 1 } 对角镜像: \left\{ \begin{matrix} x^* \\ y^* \\ 1 \end{matrix} \right\}= \left\{ \begin{matrix} -1 & 0 & M- 1 \\ 0 & -1 & N-1 \\ 0 & 0 & 1 \end{matrix} \right\} \left\{ \begin{matrix} x \\ y \\ 1 \end{matrix} \right\} xy1=100010M1N11xy1

0. 待镜像处理的原图像

在这里插入图片描述

1. 不使用MATLAB自带函数

clc,clear,close all;
Image = imread('flower.jpg');
[h, w, c] = size(Image);
deltax= 20;deltay = 40;
T1 = maketform('affine', [-1 0 0;0 1 0;w - 1 0 1]);
NewImage1 = imtransform(Image, T1, 'XData', [1 size(Image, 2)], 'YData', [1 size(Image, 1)], 'FillValue', 255);
T2 = maketform('affine', [1 0 0;0 -1 0;0 h - 1 1]);
NewImage2 = imtransform(Image, T2, 'XData', [1 size(Image, 2)], 'YData', [1 size(Image, 1)], 'FillValue', 255);
T3 = maketform('affine', [-1 0 0;0 -1 0;w - 1 h - 1 1]);
NewImage3 = imtransform(Image, T3, 'XData', [1 size(Image, 2)], 'YData', [1 size(Image, 1)], 'FillValue', 255);
subplot(221), imshow(Image), title('原图');
subplot(222), imshow(NewImage1), title('水平镜像');
subplot(223), imshow(NewImage2), title('垂直镜像');
subplot(224), imshow(NewImage3), title('对角镜像');

在这里插入图片描述

2. 使用MATLAB自带函数

% 沿维度 dim 反转 A 中元素的顺序。
B = flip(A,dim) 
flip(A,1) 将反转每一列中的元素,flip(A,2) 将反转每一行中的元素
Image = imread('flower.jpg');
subplot(221), imshow(Image), title('原图');
Image1 = flip(Image, 2);subplot(222), imshow(Image1), title('水平镜像');
Image2 = flip(Image, 1);subplot(223), imshow(Image2), title('垂直镜像');
Image3 = flip(Image1, 1);subplot(224), imshow(Image3), title('对角镜像');

在这里插入图片描述

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值