?? gp.m
字號:
clc
clear
close all
a0=imread('D:\Mary.bmp');
subplot(221);
imshow(a0);
title('原圖像');
a=imnoise(a0,'gaussian',0,0.005);
a0=double(a0);
b=zeros(1,256);
c=[b;a0;b];
%給圖像矩陣數(shù)據(jù)的最左和最右加入兩列0
d=zeros(258,1);
e=[d c d];
%建立一個3×3的平滑濾波器(模板),即3行3列的1的矩陣
panel=[-1 -1 -1;-1 8 -1;-1 -1 -1];
%進(jìn)行模板運算
for i=2:257
for j=2:257
%取出圖像中的3×3的矩陣
image33=[e(i-1,j-1) e(i-1,j) e(i-1,j+1);
e(i,j-1) e(i,j) e(i,j+1);
e(i+1,j-1) e(i+1,j) e(i+1,j+1)];
temp=0;
temp=sort(image33);
%for m=1:3
%for n=1:3
%temp= image33(m,n)*panel(m,n)+temp;
%end
%end
panelimage(i,j)=temp(5);
end
end
panelimage=mat2gray(panelimage);
subplot(222);
imshow(panelimage);
title('原中值濾波后的圖象');
%a= imnoise(a0,'salt & pepper',0.02);
subplot(223)
imshow(a);
a=double(a);
title('加噪音后的圖像');
%給圖像矩陣數(shù)據(jù)的最上和最下加入兩行0
b=zeros(1,256);
c=[b;a;b];
%給圖像矩陣數(shù)據(jù)的最左和最右加入兩列0
d=zeros(258,1);
e=[d c d];
%建立一個3×3的平滑濾波器(模板),即3行3列的1的矩陣
panel=[-1 -1 -1;-1 8 -1;-1 -1 -1];
%進(jìn)行模板運算
for i=2:257
for j=2:257
%取出圖像中的3×3的矩陣
image33=[e(i-1,j-1) e(i-1,j) e(i-1,j+1);
e(i,j-1) e(i,j) e(i,j+1);
e(i+1,j-1) e(i+1,j) e(i+1,j+1)];
temp=0;
temp=sort(image33);
%for m=1:3
%for n=1:3
%temp= image33(m,n)*panel(m,n)+temp;
%end
%end
panelimage(i,j)=temp(5);
end
end
panelimage=mat2gray(panelimage);
subplot(224);
imshow(panelimage);
title('加噪音后中值濾波圖象');
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -