[Matlab image denoising] spatial domain + frequency domain filtering image denoising [including GUI source code phase 914]

Posted by bazza84 on Thu, 06 Jan 2022 13:29:17 +0100

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. It can be seen that the image type suitable for 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 spatial domain + frequency domain filtering
It mainly includes the following four points: frequency domain transform: Fourier transform, discrete cosine transform and their inverse transform, which can transform the characteristics of image in spatial domain into frequency domain; Superimposed noise: add Gaussian noise and salt and pepper noise to the image; Spatial filtering: add smoothing filtering and sharpening filtering under different templates to the image polluted by noise, and different template sizes can be selected; Frequency domain filtering: add ideal low-pass filter, Butterworth low-pass filter, ideal high pass filter, Butterworth high pass filter, band-pass filter and band stop filter to the image polluted by noise to achieve the effect of smoothing the image.

2, Partial source code

function varargout = untitled2(varargin)
% UNTITLED2 M-file for untitled2.fig
%      UNTITLED2, by itself, creates a new UNTITLED2 or raises the existing
%      singleton*.
%
%      H = UNTITLED2 returns the handle to a new UNTITLED2 or the handle to
%      the existing singleton*.
%
%      UNTITLED2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED2.M with the given input arguments.
%
%      UNTITLED2('Property','Value',...) creates a new UNTITLED2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled2_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled2_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 untitled2

% Last Modified by GUIDE v2.5 29-Apr-202110:27:36

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled2_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled2_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 untitled2 is made visible.
function untitled2_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 untitled2 (see VARARGIN)

% Choose default command line output for untitled2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes untitled2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = untitled2_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;




%Four drop-down menus
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- 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 = get(hObject,'String') returns popupmenu3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu3


% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu4 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu4


%Menu bar (storage)
% --------------------------------------------------------------------
function SaveMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to FileMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[name,path]=uigetfile('*.*','');
file=[path,name];
axes(handles.axes1);
x=imread(file);
handles.img=x;
guidata(hObject, handles);
imshow(x);
imwrite(x,'new.jpg')
title('preservation');

%Menu bar (open)
% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to OpenMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;
global A;
file = uigetfile({'*.tif';'*.jpg';'*.bmp';'*.gif'},'Select Picture');
if ~isequal(file, 0)
    A=imread(file);
    imshow(A);
end


%Menu bar (print)
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to PrintMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printdlg(handles.figure1)

%Menu bar (off)
% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to CloseMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
                     ['Close ' get(handles.figure1,'Name') '...'],...
                     'Yes','No','Yes');
if strcmp(selection,'No')
    return;
end

delete(handles.figure1)


% --- Executes on button press in togglebutton2.
function togglebutton2_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton2

%Start denoising
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes4);
cla;

popup_sel_index = get(handles.popupmenu1, 'Value');
global P;       %Noise image
global F;       %Denoised image
global H;       %Filter template
switch popup_sel_index

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, Get code method

Matlab King assistant CSDN business card

Topics: MATLAB Computer Vision image processing