DIP第三章习题解答
數字圖像處理 第三章課后作業
下載地址:https://download.csdn.net/download/qq_44143405/1254953https://download.csdn.net/download/qq_44143405/12549535
第一題
(3-7)假設對一幅數字圖像進行直方圖均衡處理,試證明(對直方圖均衡后的圖像)進行第二次直方圖均衡處理的結果與第一次直方圖均衡處理的結果相同。
注:附錄 含 matlab 代碼及結果顯示!
第二題
(3-17)討論用一個3×3低通空間濾波器反復對一幅數字圖像處理的結果,可以不考慮邊界的影響。應用5×5濾波器時何不同?
注:附錄 含 matlab 代碼及結果顯示!
第三題
(3-19)(a)試給出求一個??領域的中值的步驟。
(b)試提出一種逐像素地移動鄰域的中心來更新中值的技術。
第四題
(3-23)在給定應用中,一個均值模板被用于輸入圖像以減少噪聲,然后再用一個拉普拉斯模板來增強圖像中的細節。如果交換一下這兩個步驟的順序,結果是否會相同?
注:附錄 含 matlab 代碼及結果顯示!
第五題
(3-6)試解釋為什么離散直方圖均衡技術一般不能得到平坦的直方圖?
注:從第一題附錄中圖可清楚的看出來!
附錄:
第一題
代碼塊:
Image=rgb2gray(imread('lotus.bmp'));histgram =imhist(Image);%%統計圖像直方圖[h,w]=size(Image);NewImage1=zeros(h,w);NewImage2=zeros(h,w);NewImage1=histeq(Image,256);%%調用Matlab函數NewImage2=histeq(NewImage1,256);imwrite(Image,'lotus0.bmp')imwrite(NewImage1,'lotus1.bmp')imwrite(NewImage2,'lotus2.bmp')figure('name','原圖像');subplot(2,1,1),imshow(Image);title('lotus灰度圖像');subplot(2,1,2),imhist(Image);title('lotus灰度圖像的直方圖');axis tight;figure('name','直方圖均衡化');subplot(2,1,1),imshow(NewImage1);title('全局直方圖均衡化處理后圖像');subplot(2,1,2),imhist(NewImage1);title('全局直方圖均衡化處理后圖像的直方圖');axis tight;figure('name','二次直方圖均衡化');subplot(2,1,1),imshow(NewImage2);title('二次全局直方圖均衡化處理后圖像');subplot(2,1,2),imhist(NewImage2);title('二次全局直方圖均衡化處理后圖像的直方圖');axis tight;(1-1)灰度圖像及直方圖
(1-2)直方圖均衡化灰度圖像及直方圖
(1-3)二次直方圖均衡化灰度圖像及直方圖
第二題
代碼塊:
Image=imread('Letters-a.jpg');noiseI=imnoise(Image,'gaussian'); ???????????????%添加高斯噪聲for i=2:51result(:,:,1)=noiseI(1:5,1:5);result(:,:,i)=filter2(fspecial('average',3),result(:,:,i-1)); ???????????????%3×3均值濾波endfigure(1);subplot(221),imshow(uint8(result(:,:,1))),title('高斯噪聲圖像');subplot(222),imshow(uint8(result(:,:,6))),title('五次3×3均值濾波圖像');subplot(223),imshow(uint8(result(:,:,11))),title('十次3×3均值濾波圖像');subplot(224),imshow(uint8(result(:,:,51))),title('五十次3×3均值濾波圖像');>> result(:,:,2)
ans =
??5×5 uint8 矩陣
????95 ??140 ??140 ??140 ???96
???151 ??219 ??219 ??219 ??151
???155 ??227 ??227 ??220 ??147
???152 ??222 ??217 ??216 ??146
????96 ??143 ??137 ??138 ???91
>> result(:,:,6)
ans =
??5×5 uint8 矩陣
????34 ???58 ???67 ???58 ???33
????58 ??100 ??115 ??100 ???58
????67 ??116 ??133 ??115 ???66
????58 ??100 ??115 ???99 ???58
34 ???58 ???67 ???58 ???33
Image=imread('Letters-a.jpg');noiseI=imnoise(Image,'gaussian'); ???????????????%添加高斯噪聲for?i=2:51result(:,:,1)=noiseI;result(:,:,i)=filter2(fspecial('average',3),result(:,:,i-1)); ???????????????%3×3均值濾波endfigure(1);subplot(221),imshow(uint8(result(:,:,1))),title('高斯噪聲圖像');subplot(222),imshow(uint8(result(:,:,6))),title('五次3×3均值濾波圖像');subplot(223),imshow(uint8(result(:,:,11))),title('十次3×3均值濾波圖像');subplot(224),imshow(uint8(result(:,:,51))),title('五十次3×3均值濾波圖像');for?i=2:51result1(:,:,1)=noiseI;result1(:,:,i)=filter2(fspecial('average',5),result(:,:,i-1)); ???????????????%3×3均值濾波endfigure(2);subplot(221),imshow(uint8(result1(:,:,1))),title('高斯噪聲圖像');subplot(222),imshow(uint8(result1(:,:,6))),title('五次5×5均值濾波圖像');subplot(223),imshow(uint8(result1(:,:,11))),title('十次5×5均值濾波圖像');subplot(224),imshow(uint8(result1(:,:,51))),title('五十次5×5均值濾波圖像');(2-1)3×3均值濾波圖像
(2-2)5×5均值濾波圖像
第三題
驗證
Input:
A = [3 2 4; 6 2 4; 8 1 9];
[M,N] = size(A);
n = M*N;
B = reshape(A,1,n);
median(B,n)
Ouput:
ans =
?????4
Input:
Image1=(rgb2gray(imread('couple.bmp')));
Image=Image1(1:9,1:9);
[height,width]=size(Image);
%%聲明新變量
result2=zeros(height,width);
n = 1;%%鄰域模板半徑
hh=height+2*n;
ww=width+2*n;
ff=zeros(hh,ww);%%圖像對外邊緣擴充ff;補零
%%賦值
ff(n+1:hh-n,n+1:ww-n)=Image;
ff(1:n,n+1:ww-n)=0;
ff(hh-n+1:hh,n+1:ww-n)=0;
ff(:,1:n)=0;
ff(:,ww-n+1:ww)=0;
ff=uint8(ff);
%%逐個取16*16鄰域中值,先從第一行開始,列逐取中值
for?i=n+1:hh-n
????for?j=n+1:ww-n ?
????????lwc=ff(i-n:i+n,j-n:j+n);%%計算子塊的局部直方圖均衡化
????????[M,N] = size(lwc);
????????nn = M*N;
????????B = reshape(lwc,1,nn);
????????result2(i-n,j-n)=median(B,nn);
????end
end
figure('name','鄰域中值處理圖像');imshow(uint8(result2));title('鄰域中值處理圖像');
imwrite(uint8(result2),'LHE.bmp');
Ouput:
原圖像灰度值(9*9)
???28 ??22 ??15 ??13 ??15 ??16 ??17 ??16 ??14
???29 ??22 ??14 ??12 ??15 ??17 ??16 ??18 ??14
???29 ??24 ??14 ??14 ??15 ??16 ??15 ??16 ??14
???27 ??23 ??14 ??12 ??15 ??15 ??15 ??16 ??14
???29 ??25 ??14 ??14 ??14 ??16 ??15 ??17 ??15
???27 ??23 ??15 ??15 ??14 ??14 ??15 ??16 ??14
???29 ??25 ??14 ??13 ??13 ??16 ??16 ??17 ??15
???27 ??25 ??15 ??13 ??13 ??15 ??16 ??16 ??13
???28 ??22 ??15 ??14 ??15 ??15 ??15 ??15 ??14
鄰域補零后圖像灰度值(11*11)
????0 ???0 ???0 ???0 ???0 ???0 ???0 ???0 ???0 ???0 ?????0
????0 ??28 ??22 ??15 ??13 ??15 ??16 ??17 ??16 ??14 ???0
????0 ??29 ??22 ??14 ??12 ??15 ??17 ??16 ??18 ??14 ???0
????0 ??29 ??24 ??14 ??14 ??15 ??16 ??15 ??16 ??14 ???0
????0 ??27 ??23 ??14 ??12 ??15 ??15 ??15 ??16 ??14 ???0
????0 ??29 ??25 ??14 ??14 ??14 ??16 ??15 ??17 ??15 ???0
????0 ??27 ??23 ??15 ??15 ??14 ??14 ??15 ??16 ??14 ???0
????0 ??29 ??25 ??14 ??13 ??13 ??16 ??16 ??17 ??15 ???0
????0 ??27 ??25 ??15 ??13 ??13 ??15 ??16 ??16 ??13 ???0
????0 ??28 ??22 ??15 ??14 ??15 ??15 ??15 ??15 ??14 ???0
????0 ???0 ???0 ???0 ???0 ???0 ???0 ???0 ???0 ????0 ????0
3*3掩膜后的圖像灰度值
?????0 ???15 ???13 ???13 ???13 ???15 ???16 ???14 ????0
????22 ???22 ???14 ???14 ???15 ???16 ???16 ???16 ???14
????23 ???23 ???14 ???14 ???15 ???15 ???16 ???15 ???14
????24 ???24 ???14 ???14 ???15 ???15 ???16 ???15 ???14
????23 ???23 ???15 ???14 ???14 ???15 ???15 ???15 ???14
????25 ???25 ???15 ???14 ???14 ???15 ???16 ???15 ???15
????25 ???25 ???15 ???14 ???14 ???15 ???16 ???16 ???14
????25 ???25 ???15 ???14 ???14 ???15 ???16 ???15 ???14
?????0 ???15 ???14 ???13 ???13 ???15 ???15 ???14 ????0
第四題
代碼塊:
% 先均值模板再用一個拉普拉斯模板處理的代碼塊Image=imread('Letters-a.jpg');noiseI=imnoise(Image,'gaussian');figure(1);subplot(221),imshow(Image),title('原圖');subplot(222),imshow(noiseI),title('高斯噪聲圖像');noiseI=im2double(noiseI);result1=filter2(fspecial('average',3),noiseI);%%3×3均值濾波subplot(223),imshow(result1),title('3×3均值濾波');% % result1=im2double(result1);H1=[0 -1 0;-1 5 -1;0 -1 0];sharpImage=imfilter(result1,H1);subplot(224),imshow(sharpImage),title('Laplacian銳化圖像');% 先用一個拉普拉斯模板再用均值模板處理的代碼塊Image=imread('Letters-a.jpg');noiseI=imnoise(Image,'gaussian'); ?figure(2),subplot(221),imshow(Image),title('原圖');subplot(222),imshow(noiseI),title('高斯噪聲圖像');noiseI=im2double(noiseI);H1=[0 -1 0;-1 5 -1;0 -1 0];sharpImage=imfilter(noiseI,H1);subplot(223),imshow(sharpImage),title('Laplacian銳化圖像');% % sharpImage=uint8(sharpImage);result1=filter2(fspecial('average',3),sharpImage); ????%%3×3均值濾波subplot(224),imshow(result1),title('3×3均值濾波');(4-1)先均值模板再拉普拉斯模板
(4-2)先拉普拉斯模板再均值模板
總結
以上是生活随笔為你收集整理的DIP第三章习题解答的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DIP第二章习题解答
- 下一篇: DIP第四章习题解答