1.领域均值滤波器
随机给图像加上椒盐噪声(灰度值为0或255)。
RGB=imread("lyy.jpg");
A=rgb2gray(RGB);
A1=A;
for i=1:1000
i=floor(rand()*m)+1;
j=floor(rand()*n)+1;
if rand()<0.5
A(i,j)=0;
else
A(i,j)=255;
end
end
subplot(121)
imshow(uint8(A1))
title('灰度图')
subplot(122)
imshow(uint8(A))
title('椒盐噪声')
1.使用领域均值滤波器处理图像。
RGB=imread("lyy.jpg");
A=rgb2gray(RGB);
A1=A;
[m,n]=size(A);
B=zeros(m,n);
for i=1:1000
i=floor(rand()*m)+1;
j=floor(rand()*n)+1;
if rand()<0.5
A(i,j)=0;
else
A(i,j)=255;
end
end
H=[1 1 1;1 1 1;1 1 1]/9;
for x=2:m-1
for y=2:n-1
B(x,y)=sum(sum(H.*double(A(x-1:x+1,y-1:y+1))));
end
end
subplot(121)
imshow(uint8(A))
title('椒盐噪声')
subplot(122)
imshow(uint8(B))
title('领域均值滤波器')
2.使用拉普拉斯算子处理图像
RGB=imread("lyy.jpg");
A=rgb2gray(RGB);
[m,n]=size(A);
B=zeros(m,n);
H=[0 1 0;1 -4 1;0 1 0];
for x=2:m-1
for y=2:n-1
B(x,y)=sum(sum(H.*double(A(x-1:x+1,y-1:y+1))));
end
end
subplot(121)
imshow(uint8(A))
title('灰度图')
subplot(122)
imshow(B,[])
title('拉普拉斯算子')