中值滤波即对于每一像素点取其邻域中值替代该像素点原值,对于椒盐噪声有极其显著的去噪效果,脱离邻域的像素点被拉回到邻域附近,图像细节,噪声都被平滑。
Matlab实现:
-
% 中值滤波 test
-
A = imread('C:\Users\gh\Desktop\photo\lena.pgm');
-
B = imnoise(A,'salt');
-
-
figure;subplot(221),imshow(A);title('原图')
-
subplot(222),imshow(B);title('椒盐噪声图')
-
-
C = m_median_filter(B,3);
-
subplot(223),imshow(C);title('中值滤波后')
-
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
%%
-
% Purpose:do median filter
-
% Author: pottor
-
% Date: 2017/5/9
-
% w is required to be odd
-
-
function out = m_median_filter(in,w)
-
-
out = in;
-
[m,n] = size(in);
-
hw = floor(w/2);
-
-
for i = 1+hw : m-hw
-
for j = 1+hw : n-hw
-
out(i,j) = median(reshape(in(i-hw:i+hw,j-hw:j+hw),[1,w*w]));
-
end
-
end
阅读(4403) | 评论(0) | 转发(0) |