7. matlab图像处理基础——几何变换+正交变换


1、几何变换

 (1)平移

  移动结果图像 = imtranslate(原始图像,移动方向)

  移动方向=[h,v]  h>0 右移  h<0 左移  v>0 下移 v<0上移

% 平移
I = imread('baby.jpg');
J = imtranslate(I,[100,50]);
% imshow(J);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

(2)旋转

  结果图像=imrotate(原始图像,旋转方向A)

  旋转方向A  A>0 逆时针  A<0 顺时针

% 旋转
I = imread('baby.jpg');
J = imrotate(I,45); % 逆时针旋转45度
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

(3)缩放

  结果图像=imresize(原始图像,缩放倍数A)

  旋转方向A  A>0 放大  A<0 缩小

% 缩放
I = imread('baby.jpg');
J = imresize(I,10); % 放大
% subplot(1,2,1),imshow(I);
% subplot(1,2,2),imshow(J);
size(I);
size(J);

(4)水平镜像

  结果图像=fliplr(原始图像)

% 水平镜像
I = imread('baby.jpg');
J = fliplr(I);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

(5)垂直镜像

  结果图像=flipud(原始图像)

% 垂直镜像
I = imread('baby.jpg');
J = flipud(I);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

2、正交变换

(1)离散余弦变换

  处理结果=dct2(原始图像)

  原始图像=idct2(离散余弦处理结果)

%% 离散余弦变换
I = imread('cameraman.tif');
J = dct2(I);
subplot(1,3,1),imshow(I);
subplot(1,3,2),imshow(J);
I2 = idct2(J);
subplot(1,3,3),imshow(I2,[]);

(2)傅里叶变换

  ① 处理结果=ff2(原始图像)

  ② 原始图像=ifft2(傅里叶变换处理结果)

  ③ 将变换的原点移到中心:

    处理结果A=fftshift(傅里叶变换结果);

    B=abs(A);

    C=log(B);

%% 傅里叶变换
I = imread('cameraman.tif');
J = fft2(I);
t = fftshift(J);
t1 = abs(t);
t2 = log(t1);
subplot(1,3,1),imshow(I);
subplot(1,3,2),imshow(t2,[]);
I2 = ifft2(J);
subplot(1,3,3),imshow(I2,[]);

(3)离散小波变换

  ① 处理结果=dwt2(原始图像,小波名字)

  ② 处理结果=[cA, cH, cV, cD]  cA——近似矩阵;cH,cV,cD——细节矩阵

    小波名字:'db1' or 'haar', 'db2', ......,'db45'

  ③ 原始图像=idwt2(离散小波变换处理结果,小波名称)

    I=idwt2(cA, cH, cD, 'db1')

  ④ 显示子带及大小

    K = [a b

      c d];

    figure,imshow[k.[ ]);

%% 离散小波变换
I = imread('cameraman.tif');
[cA,cH,cV,cD] = dwt2(I,'db1');
subplot(1,3,1),imshow(I);
test = [cA,cH,
    cV,cD];
subplot(1,3,2),imshow(test,[]);
I2 = idwt2(cA,cH,cV,cD,'db1');
subplot(1,3,3),imshow(I2,[]);

(4)提升小波变换

 

逆变换:原始图像=ilwt2(提升小波变换处理结果,小波名称)

%% 提升小波变换
I = imread('cameraman.tif');
I = double(I);
[cA,cH,cV,cD] = lwt2(I,'haar');
subplot(1,3,1),imshow(I,[]);
test = [cA,cH,
    cV,cD];
subplot(1,3,2),imshow(test,[]);
I2 = ilwt2(cA,cH,cV,cD,'db1');
subplot(1,3,3),imshow(I2,[]);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM