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,[]);

