1. 程式人生 > >數字影象處理-影象的平滑和銳化。

數字影象處理-影象的平滑和銳化。

影象的平滑和銳化是兩個相反的過程。
吃完飯再來寫註釋。。。

rice=imread('rice.png');//開啟照片。
BW=rice;//得到矩陣
G=imnoise(BW,'gaussian');//給bw矩陣新增高斯噪聲。
subplot(1,3,1);/設定2*2的單元格,顯示他們
imshow(rice);//顯示正常的
subplot(1,3,2);
imshow(G);//顯示已經新增高斯消元的.
H=averfile(G,3);//呼叫函式。
subplot(1,3,3);
imshow(H);
imrite(H,'after.png');













function D=averfile
(x,n)
a=ones(n); [M,N]=size(x); x1=double(x); x2=x1; for i=1:M-n+1 for j=1: N-n+1 C=x1(i:i+n-1,j:j+n-1).*a; s=sum(sum(C)); x2(i+((n-1)/2),j+((n-1)/2))=s/n/n; end end d=unitS(x2); BW=imread('circles.png'); Buffer=BW; subplot(1,2,1); imshow(BW); [M,N]=size(BW); for i=2:M-1
for j=2:N-1 if(BW(i,j)==255 & BW(i-1,j)==255 & BW(i+1,j)==255 & BW(i,j-1)==255 & BW(i-1,j-1)==255 & BW(i,j+1)==255 & BW(i-1,j+1)==255 & BW(i+1,j+1)==255 & BW(i+1,j-1)==255) Buffer(i,j)=0;//影象銳化。 end end end subplot(1,2,2); imshow(Buffer); l=imread('rice.png'
); G=imnoise(l,'gaussian'); subplot(2,4,1); imshow(l); [BW1,thresh1]=edge(l,'roberts');//用不同的板子得到不同的結果, [BW2,thresh2]=edge(l,'sobel'); [BW3,thresh3]=edge(l,'prewitt'); subplot(2,4,2); imshow(BW1); subplot(2,4,3); imshow(BW2); subplot(2,4,4); imshow(BW3); [BW4,thresh4]=edge(G,'roberts'); [BW5,thresh5]=edge(G,'sobel'); [BW6,thresh6]=edge(G,'prewitt'); subplot(2,4,5); imshow(BW4); subplot(2,4,6); imshow(BW5); subplot(2,4,7); imshow(BW6);