Image processing based on matlab - Gaussian noise & mean filter, salt and pepper noise & median filter

 
 
 
 
 
 
figure
oriImg=imread('peppers.bmp');% read and display the original image
subplot(1,2,1); imshow(oriImg); title ('original image');% show the original image

grayImg = rgb2gray(oriImg);% convert to grayscale image
subplot(1,2,2); imshow(grayImg); title ('grayscale image');% show grayscale image

figure
% Add Gaussian noise and use neighborhood average filtering
Inoise=imnoise(grayImg,'gaussian',0,0.02);% Add Gaussian noise to the image
subplot(1,2,1); imshow(Inoise); title('Image after adding Gaussian noise');% Display Gaussian noise image

h=ones(3,3)/8; h(2,2)=0;% construct neighborhood window
filters=imfilter(Inoise,h);% Neighborhood average filter
subplot(1,2,2); imshow(filters); title('8 Neighborhood Average Filtered Image')

figure
%Add salt and pepper noise and use median filter
Inoise=imnoise(grayImg,'salt & pepper');%Add salt and pepper noise
subplot(1,2,1); imshow(Inoise); title('The image after adding salt and pepper noise');

filters=medfilt2(Inoise,[5,5]);% median filter
subplot(1,2,2); imshow(filters); title('Median filtered image')

For the filtering method, it is necessary to use targeted methods to achieve good results. For Gaussian noise, the neighborhood mean filtering effect is better, and the filtering effect of 3x3,8 neighborhood is better after testing.
For salt and pepper noise, the median filtering effect is very good. The experimental results are shown in the figure below, for reference only.
 
 

  



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324446767&siteId=291194637