[Image denoising] Based on Gaussian filter + mean filter + median filter + bilateral filter to achieve image denoising (including signal-to-noise ratio) with Matlab code

?Author’s brief introduction: A Matlab simulation developer who loves scientific research. He cultivates his mind and technology at the same time. Matlab project cooperation can be privately messaged.

Personal homepage: Matlab Research Studio

Personal creed: Investigate knowledge.

For more Matlab simulation content click

Intelligent optimization algorithm Neural network prediction Radar communication Wireless sensor Power system

Signal Processing Image Processing Path Planning Cellular Automata UAV

? Content introduction

Combination methods based on Gaussian filtering, mean filtering, median filtering and bilateral filtering are commonly used image denoising techniques. The following are their basic principles and operating procedures:

  1. Gaussian filter: Gaussian filter uses Gaussian function to smooth the image and effectively reduce high-frequency noise. The filter reduces the influence of noise by weighting and averaging the pixels within a certain range around each pixel.

  2. Mean Filtering: Mean filtering replaces each pixel in an image with the average of its surrounding pixels to remove random noise. This filter achieves denoising by computing the neighborhood mean of pixels.

  3. Median filtering: Median filtering replaces the pixel value with the median value of the pixel values within a certain range around the central pixel to achieve the purpose of removing salt and pepper noise or impulse noise. This filter has a better removal effect on noise points with particularly large or small values.

  4. Bilateral filtering: Bilateral filtering comprehensively considers the spatial distance and pixel value similarity, and can retain the edge information of the image and reduce the spatial distance and gray level difference for filtering processing.

The procedure is as follows:

  1. Input the image to be denoised.

  2. To apply a Gaussian filter to an image, you can use an appropriate convolution kernel size and standard deviation.

  3. Applies a mean filter to the Gaussian filtered image with an appropriate neighborhood mean window.

  4. Median filtering is performed on the mean-filtered image, and an appropriate window size is selected.

  5. Finally, bilateral filtering is applied to the median-filtered image, and parameters in the spatial domain and the grayscale domain are adjusted.

  6. Output the denoised image, the result has a noise reduction effect and retains the details of the image.

It should be noted that in practical applications, depending on factors such as noise type, image content, and denoising effect requirements, it may be necessary to adjust the parameters of each filter to obtain the optimal denoising result. Better results may also be obtained by using only one filter or by combining filters in different orders. Therefore, for specific scenarios and problems, strategy adjustments and algorithm combinations can be made according to the actual situation to obtain an adaptive image denoising effect.

Use Gaussian filtering, mean filtering, median filtering, and bilateral filtering to perform denoising processing. These four types of filtering are based on adding Gaussian noise to obtain signal-to-noise ratios. And the source code can be filtered under the conditions of different convolution kernel filter sizes, different concentrations of Gaussian noise, and different filtering and denoising methods to obtain the processed image.

? Part of the code

%%%</code><code>%%% compare the application of Gaussian filter, mean filter, median filter and bilateral filter in image noise reduction</code><code>close all</code><code>clear all</code><code>clc</code><code>?</code><code>%% read image</code><code>Img = imread('1.bmp');</code><code>M = size(Img); %Get the size information of the image, if the image is in color, convert the image to a grayscale image</code><code>if numel(M)>2 </code><code> graybefore = rgb2gray(Img);</code><code>else</code><code> graybefore = Img;</code><code>end</code><code>%% Add noise to the image</code><code>gray=imnoise(graybefore, 'gaussian',0,0.02);%% salt & pepper: salt and pepper noise, gaussian: Gaussian noise, default mean 0, variance 0.01/0.02</code><code>gray=double(gray)/255; %% normalize the image</code><code>%% create a filter</code><code>W = 7;%% set the convolution kernel length W=3 /5/7</code><code>%Gaussian filter</code><code>WGaussian = fspecial('gaussian',[W,W],1);%%[W,W] represents the size of the convolution kernel, 1 represents the standard value of the filter, the larger the smoother</code><code>ResultofGaussian = imfilter(gray, WGaussian, 'replicate');%% filters the grayscale image,'re replicate' is the default value, which represents the processing selection for the boundary code><code>% Median filter</code><code>ResultofMedian=medfilt2(gray,[W W]); % Generate a median filter with a convolution kernel of 3X3</code><code>?</code><code>% Bilateral filter</code><code>w = W/2; % Half of the width of the convolution kernel </code><code>sigma = [1 0.1]; lateral = bfilter2(gray,w,sigma);</code><code>%% SNR calculation</code><code>Pic = double(graybefore)/255;</code><code>?</code><code>SNRGaussian = SNR(Pic,ResultofGaussian)</code><code>SNRAverage = SNR(Pic,ResultofAverage)</code><code> SNRMedian = SNR(Pic,ResultofMedian)</code><code>SNRBilateral = SNR(Pic,ResultofBilateral)</code><code>%% Result</code><code>figure(1)</code><code>subplot(121); </code><code>imshow(graybefore); </code><code>title('before adding noise');</code><code>subplot(122); </code><code>imshow(gray); </code><code>title('after adding noise');</code><code>?</code><code>figure(2)</code><code>subplot(121); </code><code>imshow(gray); </code><code>title('original image');</code><code>subplot( 122); </code><code>imshow(ResultofGaussian); </code><code>title('Gaussian filtered image');</code><code>?</code><code>figure(3);</code><code>subplot(121); </code><code>imshow(gray); </code><code>title('Original image');</code><code>sub plot(122); </code><code>imshow(ResultofAverage); </code><code>title('mean filtered image');</code><code>?</code><code>figure(4);</code><code>subplot(121); </code><code>imshow(gray); </code><code>title('original image');</code><code>subplot(122); </code><code>imshow(ResultofMedian); </code><code>title('median filtered image');</code><code>?</code><code>figure(5);</code><code>subplot(121); </code><code>imshow(gray); </code><code>title('original image');</code><code>subplot(122); </code><code>imshow(ResultofBilateral); </code><code>title('Bilateral filtered image');</code><code>?</code><code>figure(6)</code><code>subplot(3,2,1); </code><code>imshow(graybefore); </code><code>title('Original image') ;</code><code>subplot(3,2,2); </code><code>imshow(gray); </code><code>title('Gaussian white noise added image');</code><code>subplot(3,2,3); </code><code>imshow(ResultofGaussian); </code><code>title('Gaussian filtered image');</code><code>sub plot(3,2,4); </code><code>imshow(ResultofAverage); </code><code>title('mean filtered image');</code><code>subplot(3,2,5); </code><code>imshow(ResultofMedian); </code><code>title('median filtered image');</code><code>subplot(3,2,6 ); </code><code>imshow(ResultofBilateral); </code><code>title('Bilateral filtered image');

? Running result

? References

[1] Guan Wen. Image Noise Reduction and Pyramid HDR Imaging Algorithm for Low Illumination Solid Imaging System [D]. Beijing Institute of Technology [2023-07-06]. DOI:CNKI:CDMD:2.1016.716580.

[2] Lei Suizhu. Research and Implementation of Micro-displacement Detection System Based on Machine Vision [D]. Wuhan University of Technology, 2019.

[3] Liu Bingliang. A wavelet domain improved bilateral filter fruit image denoising algorithm [J]. Infrared Technology, 2014, 36(3):5.DOI:10.11846/j.issn.1001_8891.201403004.

[4] Yang Yongfa, Li Qi. Application of Bilateral Filtering Algorithm in Terahertz Confocal Scanning Image Denoising[J]. Progress in Laser and Optoelectronics, 2015, 52(12):6.DOI:CNKI:SUN:JGDJ.0.2015-12-015.

code to get follow me

Part of the theory quotes online literature, if there is any infringement, contact the blogger to delete it
Follow me to receive a large number of matlab e-books and mathematical modeling materials

Simulation consultation

1. Convolutional Neural Network (CNN), LSTM, Support Vector Machine (SVM), Least Squares Support Vector Machine (LSSVM), Extreme Learning Machine (ELM), Kernel Extreme Learning Machine (KELM), BP, RBF, Width Learning, DBN, RF, RBF, DELM realize wind power prediction, photovoltaic prediction, battery life prediction, radiation source identification, traffic flow prediction, load prediction, stock price prediction, PM2.5 concentration prediction, battery health status prediction, water body optical parameter inversion, N LOS signal recognition, accurate prediction of subway parking, transformer fault diagnosis
2. Image recognition, image segmentation, image detection, image hiding, image registration, image stitching, image fusion, image enhancement, image compression perception
3. Traveling Salesman Problem (TSP), Vehicle Routing Problems (VRP, MVRP, CVRP, VRPTW, etc.), UAV 3D Path Planning, UAV Collaboration, UAV Formation, Robot Path Planning, Grid Map Path Planning, Multimodal Transport Problem, Vehicle Cooperative UAV Path Planning
4. UAV path planning, UAV control, UAV formation, UAV coordination, UAV task assignment
5. Sensor deployment optimization, communication protocol optimization, routing optimization, target positioning
6. Signal recognition, signal encryption, signal denoising, signal enhancement, radar signal processing, signal watermark embedding extraction, EMG signal, EEG signal
7. Production scheduling, economic scheduling, assembly line scheduling, charging optimization, workshop scheduling, departure optimization, reservoir scheduling, three-dimensional packing, logistics location selection, cargo location optimization
8. Microgrid optimization, reactive power optimization, distribution network reconfiguration, energy storage configuration
9. Cellular automata traffic flow, crowd evacuation, virus diffusion, crystal growth