function I=denoise(X,c)
%PCNN检测噪声并去除(子函数)
if nargout == 1
c=2; %层数,也可以理解为迭代次数
end
[w,h]=size(X);
Weight =[0.707 1 0.707;1 0 1;0.707 1 0.707];%权重矩阵
beta=0.1;
alpha=0.1;
threshold0=280;
threshold=zeros(w,h);
Y = zeros(w+1,h+1);
for c1=c:-1:1
for i=2:w-1
for j=2:h-1
F=X(i,j); %F为目标点的像素值 式1
V=[Y(i-1,j-1) Y(i-1,j) Y(i-1,j+1);
Y(i,j-1) Y(i,j) Y(i,j+1);
Y(i+1,j-1) Y(i+1,j) Y(i+1,j+1)];
L=sum(sum(V.*Weight)); %式2
%sum(A) ->A矩阵每一列求和 sum(sum(A)) ->A矩阵所有元素相加
U=double(F)*(1+beta*L); %式3
if U>threshold(i,j) %式4
%点火产生脉冲
Y(i,j)=1;
if c1~=2
M=medfilt2(X(i-1:i+1,j-1:j+1)); %中值滤波
X(i,j)=M(5); %中值滤波后赋值
end
else
Y(i,j)=0;
end
threshold(i,j)=exp(-alpha)*threshold(i,j)+threshold0*Y(i,j);%式5
end
end
figure
imshow(X/255);
end
I=X;
end
原始图像
第一次PCNN点火图
第二次PCNN点火图
最终图像
参考:http://blog.sina.com.cn/s/blog_6163bdeb0100nihw.html