1, Introduction to image denoising and filtering
1 image denoising
1.1 definition of image noise
Noise is an important factor that interferes with the visual effect of image. Image denoising refers to the process of reducing noise in image. There are three kinds of noise classification: additive noise, multiplicative noise and quantization noise. We use f(x,y) to represent the image, g(x,y) to represent the image signal, and n(x,y) to represent the noise.
Image denoising refers to the process of reducing noise in digital images. The digital image in reality is often affected by the noise interference of imaging equipment and external environment in the process of digitization and transmission, which is called noisy image or noisy image. Denoising is an important content in image processing. In the process of image acquisition, transmission, transmission, reception, replication and output, noise is often generated. Salt and pepper noise is a common noise, which belongs to additive noise.
1.2 image noise source
(1) During image acquisition
In the process of image acquisition by CCD and CMOS image sensors, various noises will be introduced due to the influence of sensor material properties, working environment, electronic components and circuit structure.
(2) During image signal transmission
Due to the imperfection of transmission media and recording equipment, digital images are often polluted by a variety of noise in the process of transmission and recording.
1.3 noise classification
Noise can be classified in different forms according to different classification standards:
Based on the causes: internal noise, external noise.
Based on the relationship between noise and signal:
Additive noise: additive noise is not related to image signal strength. This kind of noisy image g can be regarded as the sum of ideal noise free image f and noise n:
g = f + n;
Multiplicative voice: multiplicative noise is related to the image signal and often changes with the change of the image signal. The noise generated by the change of the carrier carrying each pixel information is modulated by the information itself. In some cases, for example, the signal change is small and the noise is small. For the convenience of analysis and processing, multiplicative noise is often regarded as additive noise, and it is always assumed that signal and noise are statistically independent of each other.
g = f + f*n
According to the probability density function based on Statistics:
It is more important, mainly because the introduction of mathematical model is helpful to remove noise by mathematical means. In different scenes, the application methods of noise are different. Because under certain external conditions, the probability density function (statistical result) of the image original image under noise (without noise) obeys a certain distribution function, it is classified as the corresponding noise. The noise classification based on the statistical probability density function and its elimination method will be described in detail below.
1.4 classification of image denoising algorithms
(1) Spatial domain filtering
Spatial filtering is to directly perform data operation on the original image and process the gray value of pixels. Common spatial domain image denoising algorithms include neighborhood average method, median filter, low-pass filter and so on.
(2) Transform domain filtering
The image transform domain denoising method is to transform the image from the spatial domain to the transform domain, process the transform coefficients in the transform domain, and then inverse transform the image from the transform domain to the spatial domain to remove the image noise. There are many methods to transform images from spatial domain to transform domain, such as Fourier transform, Walsh Hadamard transform, cosine transform, K-L transform and wavelet transform. Fourier transform and wavelet transform are common transform methods for image denoising.
(3) Partial differential equation
Partial differential equation is an image processing method rising in recent years. It mainly aims at low-level image processing and has achieved good results. Partial differential equation has the characteristics of anisotropy. When applied in image denoising, it can remove noise and maintain the edge well. The application of partial differential equations can be divided into two categories: one is the basic iterative format, which makes the image gradually approach the desired effect through the update over time. The representative of this algorithm is Perona and Malik's equations, and the follow-up work after its improvement. This method has a large selection space in determining the diffusion coefficient. It has the function of backward diffusion while forward diffusion. Therefore, it has the ability to smooth the image and sharpen the edge. Partial differential equations have achieved good results in image processing with low noise density, but the denoising effect is not good when processing images with high noise density, and the processing time is much higher.
(4) Variational method
Another image denoising method using mathematics is to determine the energy function of the image based on the idea of variational method, and make the image reach a smooth state by minimizing the energy function. The fully variational TV model which is widely used now is this kind. The key of this kind of method is to find an appropriate energy equation to ensure the stability of evolution and obtain ideal results.
Morphological noise filter can be used to filter noise by combining open and close. Firstly, the noisy image can be opened, and the structure element matrix can be selected to be larger than the noise size. Therefore, the result of open operation is to remove the background noise; Then close the image obtained in the previous step to remove the noise on the image. Therefore, it can be seen that the image type applicable to this method is that the object size in the image is relatively large and there are no small details, so the denoising effect of this kind of image will be better.
2-value filtering
(1) Concept:
(2) Principle explanation:
3 wavelet filtering
With the increasing improvement of wavelet theory, it has attracted more and more attention in the field of image denoising with its good time-frequency characteristics, which opens up the precedent of denoising with nonlinear methods. Specifically, wavelet denoising is mainly due to the following characteristics of wavelet transform:
(1) Low entropy. The sparse distribution of wavelet coefficients reduces the entropy after image transformation. It means that after the signal (i.e. image) is decomposed, more wavelet base coefficients tend to 0 (noise), and the main parts of the signal are mostly concentrated in some wavelet bases. Using threshold denoising can better retain the original signal.
(2) Multi resolution characteristics. Due to the multi-resolution method, the nonstationarity of the signal can be well characterized, such as mutation and breakpoint (for example, 0-1 mutation cannot be reasonably represented by Fourier change). The noise can be eliminated according to the distribution of signal and noise at different resolutions.
(3) Decorrelation. Wavelet transform can decorrelate the signal, and the noise tends to whiten after transform, so wavelet domain is more conducive to denoising than time domain.
(4) Flexible selection of basis functions. Wavelet transform can flexibly select the basis function, multi band wavelet and wavelet packet can also be selected according to the signal characteristics and denoising requirements (wavelet packet decomposes the high-frequency signal again to improve the time-frequency resolution), and different wavelet basis functions can be selected for different occasions.
According to different processing methods based on wavelet coefficients, common denoising methods can be divided into three categories:
(1) Denoising based on wavelet transform modulus maxima (signal and noise modulus maxima will show different trends under wavelet transform)
(2) Denoising based on the correlation of wavelet coefficients of adjacent scales (noise has no obvious correlation among wavelet transform scales, while signal has the opposite)
(3) Threshold denoising based on Wavelet Transform
Implementation steps of wavelet denoising:
(1) Wavelet decomposition of two-dimensional signal. Select a wavelet and wavelet decomposition level N, and then calculate the decomposition of signal s to level N.
(2) Threshold quantization of high frequency coefficients. For each layer from 1 to N, a threshold is selected, and the high-frequency coefficients of this layer are soft threshold quantized.
(3) Two dimensional wavelet reconstruction. According to the low-frequency coefficients of the nth layer of wavelet decomposition and the modified high-frequency coefficients of each layer from the first layer to the nth layer, the wavelet reconstruction of two-dimensional signal is calculated.
4-wiener filtering
5 frequency domain filtering
5.1 main steps: spatial domain (Fourier transform, convolution) > > > frequency domain (multiplication with transfer function, processing, inverse Fourier transform) > > > spatial domain
5.2 common frequency domain enhancement methods:
Butterworth filter: the transfer function with order n and cutoff frequency D0 is:
(1) Low pass filtering:
The transition of low-pass Butterworth filter between high and low frequencies is relatively smooth, so the "ringing" phenomenon of the output diagram is not obvious.
The frequency domain low-pass filter can eliminate the false contour.
(2) High pass filtering:
It is to make use of the frequency characteristics of the filter to let the high frequency pass and the low frequency fail. It is like setting a threshold in the frequency domain. Each frequency component in the frequency domain has an "amplitude". The filter is like multiplying the amplitude by different gains in different frequency components. The high pass is like the gain of the high frequency part is 1 and the gain of the low frequency part is 0. Of course, this is the ideal high pass. Gaussian high pass filter is a Gaussian curve formed by connecting the gain of each frequency component in the frequency domain
High pass Butterworth filter
G( x, y ) = g ( x, y ) + c * f( x, y ) c = 0.5,0<=c<=1
(3) Band pass and band stop filtering
Band stop filter: it prevents signals within a certain frequency range from passing through and allows signals within other frequency ranges to pass through.
Band pass filter: it allows signals within a certain frequency range to pass through and prevents signals within other frequency ranges from passing through. Band pass and band stop complement each other.
Linear filters such as low-pass, high pass, band-pass and band stop can better eliminate the additive noise superimposed on the image. But in practice, noise and image are often combined in a nonlinear way. For example, in the case of light source illumination imaging, the incidence of light and the reflection of the scene contribute to the imaging in the form of multiplication, so the noise in the imaging is also multiplied with the scene.
(4) Homomorphic filtering:
It is a method to compress the image brightness range and enhance the image contrast at the same time in the frequency domain.
2, Partial source code
function varargout = dsp1(varargin) % DSP1 MATLAB code for dsp1.fig % DSP1, by itself, creates a new DSP1 or raises the existing % singleton*. % % H = DSP1 returns the handle to a new DSP1 or the handle to % the existing singleton*. % % DSP1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DSP1.M with the given input arguments. % % DSP1('Property','Value',...) creates a new DSP1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before dsp1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to dsp1_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help dsp1 % Last Modified by GUIDE v2.5 21-Mar-2014 21:34:03 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @dsp1_OpeningFcn, ... 'gui_OutputFcn', @dsp1_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before dsp1 is made visible. function dsp1_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to dsp1 (see VARARGIN) setappdata(handles.figure1,'img1',0); setappdata(handles.figure1,'img2',0); setappdata(handles.figure1,'img3',0); %set(handles.myimage_compress,'Enable', 'off'); set(handles.pushbutton_compress,'Enable', 'off'); set(handles.menu_quzaodesc, 'Enable', 'off'); set(handles.save, 'Enable', 'off'); % Choose default command line output for dsp1 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes dsp1 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = dsp1_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on selection change in popupmenu. function popupmenu_Callback(hObject, eventdata, handles) % hObject handle to popupmenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu val = get(hObject,'Value'); str = get(hObject, 'String'); switch str{val}; case 'nothing' % img2=getappdata(handles.figure1,'img1'); axes(handles.axes2); imshow(img2); setappdata(handles.figure1,'img2',img2); set(handles.pushbutton_listen, 'Enable', 'off'); case 'Gaussian noise ' % img2=getappdata(handles.figure1,'img1'); img2 = imnoise(img2,'gaussian'); %Add Gaussian noise axes(handles.axes2); imshow(img2); setappdata(handles.figure1,'img2',img2); set(handles.menu_quzaodesc, 'Enable', 'on'); set(handles.pushbutton_listen, 'Enable', 'on'); case 'Salt and pepper noise' % img2=getappdata(handles.figure1,'img1'); img2 = imnoise(img2,'salt'); axes(handles.axes2); imshow(img2); setappdata(handles.figure1,'img2',img2); set(handles.menu_quzaodesc, 'Enable', 'on'); set(handles.pushbutton_listen, 'Enable', 'on'); case 'Poisson noise' % img2=getappdata(handles.figure1,'img1'); img2 = imnoise(img2,'poisson'); axes(handles.axes2); imshow(img2); setappdata(handles.figure1,'img2',img2); set(handles.menu_quzaodesc, 'Enable', 'on'); set(handles.pushbutton_listen, 'Enable', 'on'); case 'speckle noise speckle' % img2=getappdata(handles.figure1,'img1'); img2 = imnoise(img2,'speckle'); axes(handles.axes2); imshow(img2); setappdata(handles.figure1,'img2',img2); set(handles.menu_quzaodesc, 'Enable', 'on'); set(handles.pushbutton_listen, 'Enable', 'on'); end % --- Executes during object creation, after setting all properties. function popupmenu_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % -------------------------------------------------------------------- function myfile_Callback(hObject, eventdata, handles) % hObject handle to myfile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function myfile_open_Callback(hObject, eventdata, handles) % hObject handle to myfile_open (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename, pathname] = uigetfile(... {'*.bmp;*.jpg; *.png; *.jpeg; ','Image Files(*.bmp,*.jpg,*.png,*.jpeg)';... '*.*', 'All Files(*.*)' }... , 'Pick an image');%Open file and select image if isequal(filename,0) || isequal(pathname,0) return;%If you click Cancel end axes(handles.axes1);%Important, on which axis is the image displayed fpath = [pathname filename];%Path name and file name img1 = imread(fpath);%Read image imshow(img1);%Display image setappdata(handles.figure1,'img1',img1); % --- Executes on selection change in popupmenu3. function popupmenu3_Callback(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu3 img2=getappdata(handles.figure1,'img2');%Noisy image img1=getappdata(handles.figure1,'img1');%original image val = get(hObject,'Value'); str = get(hObject, 'String'); switch str{val}; case 'median filtering ' set(handles.uipanel_lowfilt, 'Visible', 'off'); set(handles.uipanel_gausslow, 'Visible', 'off'); set(handles.pushbutton_quzao, 'Visible', 'off'); img3 = medfilt2(img2);%median filtering setappdata(handles.figure1,'img3',img3); axes(handles.axes3); imshow(img3); PSNR = psnr2(img3, img1); str1 = strcat('psnr Is: ' , num2str(PSNR) , 'db'); set(handles.text3, 'string', str1); %display PSNR value set(handles.save, 'Enable', 'on'); % set(handles.myimage_compress,'Enable', 'on'); set(handles.pushbutton_compress,'Enable', 'on'); case 'Wiener filtering ' set(handles.uipanel_lowfilt, 'Visible', 'off'); set(handles.uipanel_gausslow, 'Visible', 'off'); set(handles.pushbutton_quzao, 'Visible', 'off'); img3 = wiener2(img2,[5,5]); setappdata(handles.figure1,'img3',img3); axes(handles.axes3); imshow(img3); PSNR = psnr2(img3, img1); str1 = strcat('psnr Is: ' , num2str(PSNR) , 'db'); set(handles.text3, 'string', str1); % set(handles.myimage_compress,'Enable', 'on'); set(handles.pushbutton_compress,'Enable', 'on'); set(handles.save, 'Enable', 'on');
3, Operation results
4, matlab version and references
1 matlab version
2014a
2 references
[1] Cai Limei MATLAB image processing -- theory, algorithm and example analysis [M] Tsinghua University Press, 2020
[2] Yang Dan, Zhao Haibin, long Zhe Detailed explanation of MATLAB image processing example [M] Tsinghua University Press, 2013
[3] Zhou pin MATLAB image processing and graphical user interface design [M] Tsinghua University Press, 2013
[4] Liu Chenglong Proficient in MATLAB image processing [M] Tsinghua University Press, 2015
[5]Implementation principle of traditional image denoising algorithm based on matlab