码迷,mamicode.com
首页 > 其他好文 > 详细

Matlab实现西格玛(Sigma)平滑滤波

时间:2016-08-24 11:09:30      阅读:794      评论:0      收藏:0      [点我收藏+]

标签:

%Sigma 西格玛平滑滤波
clc;clear *;
F=rgb2gray(imread(‘img\girl.jpg‘));
figure,imshow(F); title(‘originImage‘);
F=imnoise(F,‘salt & pepper‘,0.01); %Add salt noise
figure,imshow(F); title(‘saltNoise‘);
F=double(F);
[row,col]=size(F);

for i=3:row-2 %use templet 5X5
for j=3:col-2

Templet=[F(i-2,j-2) F(i-2,j-1) F(i-2,j) F(i-2,j+1) F(i-2,j+2)
F(i-1,j-2) F(i-1,j-1) F(i-1,j) F(i-1,j+1) F(i-1,j+2)
F(i,j-2) F(i,j-1) F(i,j) F(i,j+1) F(i,j+2)
F(i+1,j-2) F(i+1,j-1) F(i+1,j) F(i+1,j+1) F(i+1,j+2)
F(i+2,j-2) F(i+2,j-1) F(i+2,j) F(i+2,j+1) F(i+2,j+2)];
Trows = reshape(Templet,5*5,1); %将模板转换成1列
theta=std2(Trows);
delta=2*theta;

count_1=0;count_0=0;
for m=1:5
for n=1:5
A=Templet(m,n)-delta;
B=Templet(m,n)+delta;
if A<=Templet(3,3)<=B
Sigma(m,n)=1;
count_1=count_1+1;
else
Sigma(m,n)=0;
count_0=count_0+1;
end
end
end

K=3;N=2;
Sum=0;Num=0;
if count_1>=K
for m=1:5
for n=1:5
Sum=Sum+Sigma(m,n)*Templet(m,n);
Num=Num+Sigma(m,n);
end
end
F(i,j)=Sum/Num;
else
F(i,j)=mean(Trows);
end

end
end

figure,imshow(uint8(F)); title(‘Sigma‘);

 

 

 

 

Matlab实现西格玛(Sigma)平滑滤波

标签:

原文地址:http://www.cnblogs.com/Qsir/p/5802028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!