A list,
First proposed by Cortes and Vapnik in 1995, Support Vector Machine (SVM) has shown many unique advantages in solving small sample, nonlinear and high-dimensional pattern recognition, and can be extended to other Machine learning problems such as function fitting.
1 Mathematics section
1.1 Two-dimensional space
2 Algorithm part
Ii. Source code
function varargout = DigitClassifyUI(varargin)
%
% DIGITCLASSIFYUI MATLAB code for DigitClassifyUI.fig
% DIGITCLASSIFYUI, by itself, creates a new DIGITCLASSIFYUI or raises the existing
% singleton*.
%
% H = DIGITCLASSIFYUI returns the handle to a new DIGITCLASSIFYUI or the handle to
% the existing singleton*.
%
% DIGITCLASSIFYUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DIGITCLASSIFYUI.M with the given input arguments.
%
% DIGITCLASSIFYUI('Property'.'Value',...). creates anew DIGITCLASSIFYUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DigitClassifyUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DigitClassifyUI_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 DigitClassifyUI
% Last Modified by GUIDE v2. 5 10-Feb- 2021. 18:44:08
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DigitClassifyUI_OpeningFcn, ...
'gui_OutputFcn', @DigitClassifyUI_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 DigitClassifyUI is made visible.
function DigitClassifyUI_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 DigitClassifyUI (see VARARGIN)
% Choose default command line output for DigitClassifyUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DigitClassifyUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global FigHandle AxesHandle RectHandle;
FigHandle = handles.output;
AxesHandle = handles.axes_write;
MouseDraw();
axis(handles.axes_write,[1 400 1 400]); RectHandle = Rectangle (handles. Axes_write,'Position'[80.66.240.268].'LineStyle'.The '-'.'EdgeColor'.'#a9a9a9');
% --- Outputs from this function are returned to the command line.
function varargout = DigitClassifyUI_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 button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (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 pushbutton_loadImage.
function pushbutton_loadImage_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_loadImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global RectHandle;
cla(handles.axes_write, 'reset')
set(handles.axes_write, 'Visible'.'off');
set(handles.output, 'Pointer'.'arrow');
axis(handles.axes_write,[1 400 1 400]); RectHandle = Rectangle (handles. Axes_write,'Position'[80.66.240.268].'LineStyle'.The '-'.'EdgeColor'.'#a9a9a9'); % Popup file selection box, select a picture [file,path] = uigetFile ({'*.jpg; *.jpeg; *.png; *.bmp; *.tif'.'Image files (*.jpg,*.jpeg,*.png,*.bmp,*.tif)'},'Select a picture');
if isequal(file,0)% If the file does not existset(handles.edit_imagePath, 'String'.'Please select a picture');
elsefileName= fullfile(path, file); % The absolute path of the selected imageset(handles.edit_imagePath, 'String', fileName); InputImage = imread(fileName); image(handles.axes_raw, InputImage);set(handles.axes_raw, 'Visible'.'off');
set(gcf, 'Pointer'.'arrow');
set(gcf, 'WindowButtonMotionFcn'.'') set(gcf, 'WindowButtonUpFcn'.If numel(size(InputImage))==3 InputImage = rGB2Gray (InputImage); Axes (handles. Axes_gray); imshow(InputImage); else axes(handles.axes_gray); imshow(InputImage); End % binarization InputImage = imbinarize(InputImage); axes(handles.axes_binary); imshow(InputImage); % feature extraction InputImage = imresize(InputImage, [28, 28]); cellSize = [4 4]; [~, vis4x4] = extractHOGFeatures(InputImage,'CellSize'[4 4]);
axes(handles.axes_features);
plot(vis4x4);
load('trainedSvmModel.mat'.'classifier');
features(1, :) = extractHOGFeatures(InputImage,'CellSize',cellSize);
predictedLabel = predict(classifier, features);
str = string(predictedLabel);
set(handles.text_result, 'String', str);
end
axes(handles.axes_write);
MouseDraw();
% set(gcf, 'WindowButtonDownFcn'."); % --- Executes on button press in pushbutton_load. function pushbutton_load_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_load (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global RectHandle; axis(handles.axes_write,[1 400 1 400]); Set (handles. Edit_imagePath, 'handles.String'.'Please select a picture');
delete(RectHandle);
h=getframe(handles.axes_write);
imwrite(h.cdata,'writedImage.jpg');
InputImage = imread('writedImage.jpg');
% InputImage = cat(3, InputImage,InputImage,InputImage);
image(handles.axes_raw,InputImage);
set(handles.axes_raw, 'Visible'.'off');
axis(handles.axes_write,[1 400 1 400]); RectHandle = Rectangle (handles. Axes_write,'Position'[80.66.240.268].'LineStyle'.The '-'.'EdgeColor'.'#a9a9a9');
global FigHandle
set(FigHandle, 'Pointer'.'arrow');
set(FigHandle, 'WindowButtonMotionFcn'.'')
set(FigHandle, 'WindowButtonUpFcn'.'')
set(FigHandle, 'WindowButtonDownFcn'."); If numel(size(InputImage))==3 InputImage = rGB2Gray (InputImage); Axes (handles. Axes_gray); imshow(InputImage); else axes(handles.axes_gray); imshow(InputImage); End % binarization InputImage = imbinarize(InputImage); axes(handles.axes_binary); imshow(InputImage); % feature extraction InputImage = imresize(InputImage, [28, 28]); cellSize = [4 4]; [~, vis4x4] = extractHOGFeatures(InputImage,'CellSize'[4 4]);
axes(handles.axes_features);
plot(vis4x4);
load('trainedSvmModel.mat'.'classifier');
features(1, :) = extractHOGFeatures(InputImage,'CellSize',cellSize);
predictedLabel = predict(classifier, features);
str = string(predictedLabel);
set(handles.text_result, 'String', str);
MouseDraw();
% --- Executes on button press in pushbutton_clear.
function pushbutton_clear_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_clear (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global RectHandle;
global FigHandle
set(FigHandle, 'Pointer'.'arrow');
set(FigHandle, 'WindowButtonMotionFcn'.'')
set(FigHandle, 'WindowButtonUpFcn'.'')
set(FigHandle, 'WindowButtonDownFcn'."); set(handles.edit_imagePath, 'String'.'Please select a picture');
set(handles.text_result, 'String'.'None');
cla(handles.axes_write, 'reset')
set(handles.axes_write, 'Visible'.'off');
cla(handles.axes_raw, 'reset')
set(handles.axes_raw, 'Visible'.'off');
cla(handles.axes_gray, 'reset')
set(handles.axes_gray, 'Visible'.'off');
cla(handles.axes_binary, 'reset')
set(handles.axes_binary, 'Visible'.'off');
cla(handles.axes_features, 'reset')
set(handles.axes_features, 'Visible'.'off');
set(handles.output, 'Pointer'.'arrow');
axis(handles.axes_write,[1 400 1 400]); RectHandle = Rectangle (handles. Axes_write,'Position'[80.66.240.268].'LineStyle'.The '-'.'EdgeColor'.'#a9a9a9');
MouseDraw();
Copy the code
Third, the operation result
Fourth, note
Version: 2014 a