當前位置:菜譜大全網 - 饑荒食譜 - 程序:灰度圖像椒鹽噪聲matlab

程序:灰度圖像椒鹽噪聲matlab

發送平均過濾程序。這個程序是我寫的,用於邊緣檢測。壹開始我用高斯濾波器做平均濾波,LZ可以借鑒壹下。發程序~ ~ ~ ~

色度控制中心

全部關閉

清理所有

%%%生成高斯平滑濾波器模板%%%

%%%%%%%%%%%%%%%%%%%%%%%%%

hg =零(3,3);%將高斯平滑濾波器模板的大小設置為3*3。

δ= 0.5;

因為x=1:1:3

因為y=1:1:3

u = x-2;

v = y-2;

hg(x,y)=exp(-(u^2+v^2)/(2*pi*delta^2));

結束

結束

h = Hg/sum(Hg(:));

%%%%%%%%%%%%%

%%%%%%%%%%%%%讀入圖像%%%%%%%%%%

%%%%%%%%%%%%%

f = imread(' 1111 . TIF ');%讀入圖像文件

f = RGB 2 gray(im 2 double(f));

imshow(f)

標題(“原圖”);

[m,n]=大小(f);

ftemp=zeros(m,n);

row high = m-1;

col high = n-1;

%%%高斯濾波%%%

對於x=2:1:rowhigh-1

對於y=2:1:colhigh-1

mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1);f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];

A = h. * mod

ftemp(x,y)= sum(A(:);

結束

結束

f=ftemp

圖,imshow(f)

標題('高斯濾波後的圖像');

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%使用roberts算子進行邊緣檢測%%%

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

sx =[-1-2-1;0 0 0;1 2 1];

sy =[-1 0 1;-2 0 2;-1 0 1];

對於x=2:1:rowhigh-1

對於y=2:1:colhigh-1

mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1);f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];

fsx=sx。* mod

fsy=sy。* mod

ftemp(x,y)=sqrt((sum(fsx(:)))^2+(sum(fsy(:)))^2);

結束

結束

fr = im 2 uint 8(ft EMP);

圖,imshow(法國)

標題(“roberts算子邊緣檢測到的原始圖像”);

%%%域值劃分%%%

th 1 = 60;%設置閾值

對於x=2:1:rowhigh-1

對於y=2:1:colhigh-1

if (fr(x,y)>= th 1)& amp;((fr(x,y-1)& lt;= fr(x,y))& amp;(fr(x,y)>fr(x,y+1)))

fr(x,y)= 200;

elseif(fr(x,y)>= th 1)& amp;((fr(x-1,y)& lt;=fr(x,y))& amp;(fr(x,y)>fr(x+1,y)))

fr(x,y)= 200;

else fr(x,y)= 50;

結束

結束

結束

圖,imshow(法國)

標題(“用roberts算子進行邊緣檢測和細化後的圖像”);