數(shù)字圖像處理實驗四
(圖像變換)
實驗內(nèi)容:
- 對圖像lena、cameraman和face進行傅里葉變換,觀察圖像能量在頻譜圖中的分布情況。
- 利用Matlab生成下列圖像,并對其進行旋轉(zhuǎn)30度、90度和120度,然后對他們分別進行傅里葉變換。
- 對圖像lena、cameraman和face用DCT變換進行圖像壓縮,舍掉的變換系數(shù)分別小于0.01、0.03、0.05,求經(jīng)壓縮、解壓后的圖像。
實驗步驟:
- 對給定圖像進行傅里葉變換并觀察圖像能量在頻譜圖中的分布情況。
P1 =imread('./face.jpg');
P1=im2double(P1);
P2 =imread('./cameraman.tif');
P2=im2double(P2);
P3 =imread('./lena.jpg');
P3=im2double(P3);
P1f = fft2(P1);
P2f = fft2(P2);
P3f = fft2(P3);
P1f1 =abs(P1f);
P2f1 = abs(P2f);
P3f1 = abs(P3f);
P1f2 = fftshift(P1f1);
P2f2 = fftshift (P2f1);
P3f2 = fftshift(P3f1);
figure;
subplot(3,3,1);
imshow(P1);
xlabel('原圖face ');
subplot(3,3,2);
imshow(P2);
xlabel('原圖cameraman');
subplot(3,3,3);
imshow(P3);
xlabel('原圖lena');
subplot(3,3,4);
imshow(P1f,[5,30]);
xlabel('頻譜圖face');
subplot(3,3,5);
imshow(P2f,[5,30]);
xlabel('頻譜圖cameraman');
subplot(3,3,6);
imshow(P3f,[5,30]);
xlabel('頻譜圖lena');
subplot(3,3,7);
imshow(P1f2,[5,30]);xlabel('中心移到零點face');
subplot(3,3,8);
imshow(P2f2,[5,30]);
xlabel('中心移到零點cameraman');
效果圖:
2.matlab生成圖像并進行傅里葉旋轉(zhuǎn)變換
Picture = zeros(256,256);
Picture(28:228,108:148) = 1;
%旋轉(zhuǎn)
P1=imrotate(Picture,30,'bilinear');
P2=imrotate(Picture,90,'bilinear');
P3=imrotate(Picture,120,'bilinear');
%傅里葉變換
Picturef=fft2(Picture);F=abs(Picturef);
Picturef=fftshift(F);
P1f=fft2(P1);F=abs(P1f);P1f=fftshift(F);
P2f=fft2(P2);F=abs(P2f);P2f=fftshift(F);
P3f=fft2(P3);F=abs(P3f);P3f=fftshift(F);
%顯示圖像
figure;
subplot(2,4,1);imshow(Picture);xlabel('原圖 ');
subplot(2,4,2);imshow(P1);xlabel('旋轉(zhuǎn)30度 ');
subplot(2,4,3);imshow(P2);xlabel('旋轉(zhuǎn)90度');
subplot(2,4,4);imshow(P3);xlabel('旋轉(zhuǎn)120度');
subplot(2,4,5);imshow(Picturef,[5,50]);xlabel('原圖的傅里葉頻譜');
subplot(2,4,6);imshow(P1f,[5,50]);xlabel('旋轉(zhuǎn)30度');
subplot(2,4,7);imshow(P2f,[5,50]);xlabel('旋轉(zhuǎn)90度');
subplot(2,4,8);imshow(P3f,[5,50]);xlabel('旋轉(zhuǎn)120度');
效果圖:
3.對給定的圖像按要求進行DCT變換實現(xiàn)圖像壓縮(三張圖代碼類似這里給出來一個)
I =imread('./lena.jpg');
[M,N]=size(I);%M=512,N=512
I=im2double(I);
%生成標準DCT變化中的矩陣(8x8)
n=8;
[cc,rr]=meshgrid(0:n-1);
C=sqrt(2/n)*cos(pi*(2*cc+1).*rr/(2*n));
C(1,:)=C(1,:)/sqrt(2);
%光亮度量化表
a=[16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99 ];
%分塊做DCT變換(8x8) DCT變換公式 正變換Y=CIC'
for i=1:8:M
for j=1:8:N
P=I(i:i+7,j:j+7);
K=C*P*C';
I1(i:i+7,j:j+7)=K;
K=K./a; %量化(按位除)
K(abs(K)<0.01)=0; %舍掉的變換系數(shù)分別小于0.01 0.03 0.05
I2(i:i+7,j:j+7)=K;
end
end
%分塊做DCT反變換(8x8),逆變換 P=C'YC
for i=1:8:M
for j=1:8:N
P=I2(i:i+7,j:j+7).*a;%反量化
K=C'*P*C;
I3(i:i+7,j:j+7)=K;
end
end
figure(1);
subplot(2,2,1);imshow(I);xlabel('原圖 ');
subplot(2,2,2);imshow(I1);xlabel('DCT變換后的頻域圖像 ');
subplot(2,2,3);imshow(I2);xlabel('量化后的頻域圖像 ');
subplot(2,2,4);imshow(I3);xlabel('復(fù)原圖像 ');
效果圖:文章來源:http://www.zghlxwxcb.cn/news/detail-851130.html
問題討論:
圖像變換是將圖像從空間變換到變換域(或頻率域),變換的目的是根據(jù)圖像在變換域的某些性質(zhì)對其進行處理。傅里葉變換是使用最廣泛地一種變換,可廣泛應(yīng)用于圖像特征提取、圖像增強等方面,離散余弦變換在圖像壓縮算法中獲得了廣泛的應(yīng)用。文章來源地址http://www.zghlxwxcb.cn/news/detail-851130.html
到了這里,關(guān)于數(shù)字圖像處理實驗四--圖像變換的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!