当前位置:网站首页>Analysis of 43 cases of MATLAB neural network: Chapter 19 handwritten font recognition based on SVM
Analysis of 43 cases of MATLAB neural network: Chapter 19 handwritten font recognition based on SVM
2022-06-21 22:42:00 【mozun2020】
《MATLAB neural network 43 A case study 》: The first 19 Chapter be based on SVM Handwritten font recognition
1. Preface
《MATLAB neural network 43 A case study 》 yes MATLAB Technology Forum (www.matlabsky.com) planning , Led by teacher wangxiaochuan ,2013 Beijing University of Aeronautics and Astronautics Press MATLAB A book for tools MATLAB Example teaching books , Is in 《MATLAB neural network 30 A case study 》 On the basis of modification 、 Complementary , Adhering to “ Theoretical explanation — case analysis — Application extension ” This feature , Help readers to be more intuitive 、 Learn neural networks vividly .
《MATLAB neural network 43 A case study 》 share 43 Chapter , The content covers common neural networks (BP、RBF、SOM、Hopfield、Elman、LVQ、Kohonen、GRNN、NARX etc. ) And related intelligent algorithms (SVM、 Decision tree 、 Random forests 、 Extreme learning machine, etc ). meanwhile , Some chapters also cover common optimization algorithms ( Genetic algorithm (ga) 、 Ant colony algorithm, etc ) And neural network . Besides ,《MATLAB neural network 43 A case study 》 It also introduces MATLAB R2012b New functions and features of neural network toolbox in , Such as neural network parallel computing 、 Custom neural networks 、 Efficient programming of neural network, etc .
In recent years, with the rise of artificial intelligence research , The related direction of neural network has also ushered in another upsurge of research , Because of its outstanding performance in the field of signal processing , The neural network method is also being applied to various applications in the direction of speech and image , This paper combines the cases in the book , It is simulated and realized , It's a relearning , I hope I can review the old and know the new , Strengthen and improve my understanding and practice of the application of neural network in various fields . I just started this book on catching more fish , Let's start the simulation example , Mainly to introduce the source code application examples in each chapter , This paper is mainly based on MATLAB2015b(32 position ) Platform simulation implementation , This is Chapter 19 of the book based on SVM An example of handwriting font recognition , Don't talk much , Start !
2. MATLAB Simulation example
open MATLAB, Click on “ Home page ”, Click on “ open ”, Find the sample file 
Choose Chapter_CharacterRecognitionUsingLibsvm.m, Click on “ open ”
Chapter_CharacterRecognitionUsingLibsvm.m Source code is as follows :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Chapter_CharacterRecognitionUsingLibsvm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function : be based on SVM Handwritten font recognition
% Environmental Science :Win7,Matlab2015b
%Modi: C.S
% Time :2022-06-17
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Matlab neural network 43 A case study
% be based on SVM Handwritten font recognition
% by Li Yang (faruto)
% http://www.matlabsky.com
% Email:[email protected]163.com
% http://weibo.com/faruto
% http://blog.sina.com.cn/faruto
% 2013.01.01
%% A Little Clean Work
close all;
clear;
clc;
format compact;
%% Load training data
tic
% utilize uigetfile Function to select training samples interactively
[FileName,PathName,FilterIndex] = uigetfile( ...
{
'*.jpg';'*.bmp'},' Please import training pictures ','*.jpg','MultiSelect','on');
if ~FilterIndex
return;
end
num_train = length(FileName);
TrainData = zeros(num_train,16*16);
TrainLabel = zeros(num_train,1);
for k = 1:num_train
pic = imread([PathName,FileName{
k}]);
pic = pic_preprocess(pic);
% Pull the normalized image into a vector by column and transpose , Generate 50*256 Training sample matrix of
TrainData(k,:) = double(pic(:)');
% The sample label is the number corresponding to the sample
TrainLabel(k) = str2double(FileName{
k}(4));
end
%% Establish support vector machine
% [bestCVaccuracy,bestc,bestg] = ...
% SVMcgForClass(TrainLabel,TrainData,-8,8,-8,8,10,0.8,0.8,4.5)
% Set up GA Related parameters
ga_option.maxgen = 100;
ga_option.sizepop = 20;
ga_option.cbound = [0,100];
ga_option.gbound = [0,100];
ga_option.v = 10;
ga_option.ggap = 0.9;
[bestCVaccuracy,bestc,bestg] = ...
gaSVMcgForClass(TrainLabel,TrainData,ga_option)
% Training
cmd = ['-c ',num2str(bestc),' -g ',num2str(bestg)];
model = svmtrain(TrainLabel, TrainData, cmd);
% View recognition on the training set
preTrainLabel = svmpredict(TrainLabel, TrainData, model);
%% Load test samples
[FileName,PathName,FilterIndex] = uigetfile( ...
{
'*.jpg';'*.bmp'},' Please import test pictures ','*.bmp','MultiSelect','on');
if ~FilterIndex
return;
end
num_train = length(FileName);
TestData = zeros(num_train,16*16);
TestLabel = zeros(num_train,1);
for k = 1:num_train
pic = imread([PathName,FileName{
k}]);
pic = pic_preprocess(pic);
TestData(k,:) = double(pic(:)');
TestLabel(k) = str2double(FileName{
k}(4));
end
%% Classify the test samples
preTestLabel = svmpredict(TestLabel, TestData, model);
assignin('base','TestLabel',TestLabel);
assignin('base','preTestLabel',preTestLabel);
TestLabel'
preTestLabel'
%% sub function of pre-processing pic
function pic_preprocess = pic_preprocess(pic)
% Image preprocessing subfunction
% Image inversion processing
pic = 255-pic;
% Set threshold , Convert an inverse color image into a binary image
pic = im2bw(pic,0.4);
% Find the row mark of all pixels on the number y And column labels x
[y,x] = find(pic == 1);
% Intercept the smallest area containing the complete number
pic_preprocess = pic(min(y):max(y), min(x):max(x));
% Convert the intercepted minimum area image containing complete numbers into 16*16 Standardized image
pic_preprocess = imresize(pic_preprocess,[16,16]);
toc
Add completed , Click on “ function ”, Start emulating , The following prompt appears in the pop-up box : Please import training pictures 
choice “ Handwritten numeral training sample pictures ” Folder , Select all pictures , Click on “ open ”
Waiting to run , The following results appear 
The following pop-up prompt appears : Please import test pictures 
choice “ Handwritten numeral test sample pictures ” Folder , Select all pictures , Click on “ open ”
The output simulation results are as follows :
Accuracy = 93.3333% (28/30) (classification)
ans =
1 to 19 Column
0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6
20 to 30 Column
6 6 7 7 7 8 8 8 9 9 9
ans =
1 to 19 Column
0 0 0 1 1 7 2 2 2 3 3 3 4 4 4 5 5 5 6
20 to 30 Column
6 6 7 7 7 8 8 8 7 9 9
3. Summary
Simple handwritten numeral recognition application , First, train , Then carry out prediction, classification and identification , Get the results of classification , The whole process has been fully implemented , If you choose a single picture by yourself, you will report an error , So when you do the simulation , Remember to select all pictures . Interested in the content of this chapter or want to fully learn and understand , It is suggested to study the contents of Chapter 19 in the book . Some of these knowledge points will be supplemented on the basis of their own understanding in the later stage , Welcome to study and exchange together .
边栏推荐
- Use the for loop to calculate n! Value of
- FPGA之道——FPGA开发流程之项目方案与FPGA设计方案
- Six possible challenges when practicing Devops
- 【电子方案设计】酒精测试仪PCBA解决方案
- fork-join线程池
- KVM虚拟机救援模式修改root密码 —— 筑梦之路
- GDB debugging practice (10) multi thread debugging
- [WUSTCTF2020]朴实无华-1
- 可乐与凉茶加速互卷
- Swiftui basic learning journal (XI) SQLite data operation
猜你喜欢

LeetCode-543-二叉树的直径

The way of FPGA -- project scheme and FPGA design scheme of FPGA development process

Migration of stm32f407 program to stm32f429

Nacos installation guide
![[deeply understand tcapulusdb technology] transaction execution of document acceptance](/img/7c/25a88f46e02cebd2e003b9590b9c13.png)
[deeply understand tcapulusdb technology] transaction execution of document acceptance

KVM虚拟机救援模式修改root密码 —— 筑梦之路

Implement a middleware from -1

UWP 阴影效果

WPF thread manipulation UI problem
![[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor](/img/74/a645742a8e135b32154859be956760.png)
[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor
随机推荐
promise错误捕获处理——Promisifying技术
WPF ListBox虚拟化
UEFI dual system + dual hard disk installation
流式细胞分析Flowjo 10介绍以及超详细图文安装激活教程
WPF x:ArrayExtension
Sampler collection
UWP 确认是否有弹窗显示
Contact five heart matchmaker to take off the order
个人的股票交易经验
[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor
Install RkNN toolkit Lite2 for itop-3568 development board
ES7 create index template
Technology sharing | a clustering incremental statistical SQL requirement in MySQL
小程序与工业互联网能够相辅相成的原因
解决opencv在pycharm中代码提示失效
[deeply understand tcapulusdb technology] transaction execution of document acceptance
Uwp shadow effect
GDB debugging practice (10) multi thread debugging
Fedora 36 compiling and installing opencv 4.6.0 -- the road to building a dream
Uwp confirms whether there is pop-up display