1, Introduction
Mean filtering refers to the pixel value of any point, which is the surroundingThe average of the pixel values. For example, in the following figure, the pixel value of a red dot is the sum of the pixel values of the surrounding blue background area divided by 25, 25 = 55 is the size of the blue area.
The detailed calculation method of mean filtering is shown in the figure below:
Of which 5The matrix of 5 is called kernel. For the pixels in the original image, the kernel is used to process and obtain the result image, as shown in the following figure:
Extracting ^ 1 / 25 ^ can convert the core into the following form:
3 median filtering
While using the neighborhood average method to denoise, it also makes the boundary blurred. Median filter is a nonlinear image processing method, which can take into account the preservation of boundary information while denoising. Select a window with odd points, scan the window on the image, arrange the pixels in the window in ascending or descending order of gray level, and take the gray value in the middle to replace the gray value of the point. The calculation process is shown in the figure below:
4 Gaussian filtering
In order to overcome the disadvantages of simple local average method (image blur), many local smoothing algorithms that maintain edges and details have been proposed. Their starting points focus on how to select the size, shape and direction of the neighborhood, the parameter plus average and the weight coefficient of each store in the neighborhood.
Image Gaussian smoothing is also a method of image smoothing based on the idea of neighborhood average. In image Gaussian smoothing, pixels at different positions are given different weights when averaging the image. Gaussian smoothing is different from simple smoothing. When averaging pixels in the neighborhood, it gives different weights to pixels in different positions, as shown in 3 in the following figure3 and 55 neighborhood Gaussian template.
(1) The nuclear size is 33
(1) The nuclear size is 55
Gaussian filtering makes the adjacent pixels have higher importance, calculates the weighted average value of the surrounding pixels, and the closer pixels have larger weight values. As shown in the figure below, the center position weight is up to 0.4.
2, Source code
function varargout = ImageProcess(varargin) % IMAGEPROCESS MATLAB code for ImageProcess.fig % IMAGEPROCESS, by itself, creates a new IMAGEPROCESS or raises the existing % singleton*. % % H = IMAGEPROCESS returns the handle to a new IMAGEPROCESS or the handle to % the existing singleton*. % % IMAGEPROCESS('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in IMAGEPROCESS.M with the given input arguments. % % IMAGEPROCESS('Property','Value',...) creates a new IMAGEPROCESS or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before ImageProcess_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to ImageProcess_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 ImageProcess % Last Modified by GUIDE v2.5 28-May-2015 23:28:37 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @ImageProcess_OpeningFcn, ... 'gui_OutputFcn', @ImageProcess_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 ImageProcess is made visible. function ImageProcess_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 ImageProcess (see VARARGIN) % Choose default command line output for ImageProcess global ImagesShownCnt; ImagesShownCnt = 0; set(handles.axes1,'visible','off') set(handles.axes2,'visible','off') set(handles.axes3,'visible','off') set(handles.axes4,'visible','off') set(handles.axes5,'visible','off') set(handles.axes6,'visible','off') set(handles.axesSrcImg,'visible','off') setappdata(0,'thr',0.0); handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes ImageProcess wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = ImageProcess_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; % -------------------------------------------------------------------- function File_Callback(hObject, eventdata, handles) % hObject handle to File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Open_Callback(hObject, eventdata, handles) % hObject handle to Open (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Save_Callback(hObject, eventdata, handles) % hObject handle to Save (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Save_As_Callback(hObject, eventdata, handles) % hObject handle to Save_As (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global srcImg; global dstImg; global doubledstImg; global doublesrcImg; % IMGTYPE % 0 Gray % 1 Color global IMGTYPE; [filename, pathname] = uigetfile({'*.bmp;*.jpg;*.png;*.jpeg;*.tif'},'Pick an image'); if isequal(filename,0)||isequal(pathname,0) return; end fpath=[pathname filename]; srcImg=imread(fpath); axes(handles.axesSrcImg); imshow(srcImg); if length(size(srcImg))>2 IMGTYPE = 1; else IMGTYPE = 0; end dstImg = srcImg; doubledstImg = im2double(dstImg); doublesrcImg = im2double(srcImg); %title('original image ','fontsize',8); % --- Executes on button press in pushbuttonSave. function pushbuttonSave_Callback(hObject, eventdata, handles) % hObject handle to pushbuttonSave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function varargout = getthreshold(varargin) % GETTHRESHOLD MATLAB code for getthreshold.fig % GETTHRESHOLD, by itself, creates a new GETTHRESHOLD or raises the existing % singleton*. % % H = GETTHRESHOLD returns the handle to a new GETTHRESHOLD or the handle to % the existing singleton*. % % GETTHRESHOLD('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GETTHRESHOLD.M with the given input arguments. % % GETTHRESHOLD('Property','Value',...) creates a new GETTHRESHOLD or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before getthreshold_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to getthreshold_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 getthreshold % Last Modified by GUIDE v2.5 25-May-2015 21:49:34 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @getthreshold_OpeningFcn, ... 'gui_OutputFcn', @getthreshold_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 getthreshold is made visible. function getthreshold_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 getthreshold (see VARARGIN) % Choose default command line output for getthreshold handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes getthreshold wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = getthreshold_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; function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit 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 % --- Executes on button press in pushbuttonDonoho. function pushbuttonDonoho_Callback(hObject, eventdata, handles) % hObject handle to pushbuttonDonoho (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global doubledstImg; thresh = Donoho(doubledstImg); set(handles.edit1,'string',num2str(thresh));
3, Operation results