O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Very Simple Automatic English Optical Character
Recognition (OCR) System Using Artificial Neural Net-
works (ANNs)
2013
By...
OCR Using FFBP Neural Network
This file contains a simple description about what I have created about how to
recognize cha...
This process is done for all the dataset elements.
The features of the first dataset image is placed in a 15x36 feature ar...
After training the data the network and saving it, it will be ready for working.
Recognition Process
1. Extract each chara...
MATLAB Code
Image Characters Extraction
function croppedChar = charExtractor(char)
sig=imread(char);
bSig = im2bw(sig);
im...
findBottoms=findBottoms+2;
end
%% Step 3:Here, I have created the testClipper.m function that is used to cut the spaces be...
imagePortion=imread('clippedPortions.png');
info=imfinfo('clippedPortions.png');
NonZeroMeanFound=0;
sigMean=0;
detectedPo...
4,16,10,11,12,6,4,17,3,5,10,0,6,0,0,0,4,0,0,14,0,0,0,0,4,0,6,0,8,16,2,10,3,11,14,9
2,16,9,11,12,6,2,11,2,3,8,0,4,0,0,0,6,0...
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...
outputString=strcat(outputString,'0');
case 1
outputString=strcat(outputString,'1');
case 2
outputString=strcat(outputStri...
outputString=strcat(outputString,'O');
case 25
outputString=strcat(outputString,'P');
case 26
outputString=strcat(outputSt...
outputString=strcat(outputString,'m');
case 49
outputString=strcat(outputString,'n');
case 50
outputString=strcat(outputSt...
Próximos SlideShares
Carregando em…5
×

MATLAB Code + Description : Very Simple Automatic English Optical Character Recognition (OCR) System using Artificial Neural Networks (ANNs)

This file contains a simple description about what I have created about how to recognize characters using feed forward back propagation neural network as a pattern recognition project when being undergraduate student at 2013.
The MATLAB code of the system is also available in the document.

Find me on:
AFCIT
http://www.afcit.xyz

YouTube
https://www.youtube.com/channel/UCuewOYbBXH5gwhfOrQOZOdw

Google Plus
https://plus.google.com/u/0/+AhmedGadIT

SlideShare
https://www.slideshare.net/AhmedGadFCIT

LinkedIn
https://www.linkedin.com/in/ahmedfgad/

ResearchGate
https://www.researchgate.net/profile/Ahmed_Gad13

Academia
https://www.academia.edu/

Google Scholar
https://scholar.google.com.eg/citations?user=r07tjocAAAAJ&hl=en

Mendelay
https://www.mendeley.com/profiles/ahmed-gad12/

ORCID
https://orcid.org/0000-0003-1978-8574

StackOverFlow
http://stackoverflow.com/users/5426539/ahmed-gad

Twitter
https://twitter.com/ahmedfgad

Facebook
https://www.facebook.com/ahmed.f.gadd

Pinterest
https://www.pinterest.com/ahmedfgad/

  • Entre para ver os comentários

MATLAB Code + Description : Very Simple Automatic English Optical Character Recognition (OCR) System using Artificial Neural Networks (ANNs)

  1. 1. Very Simple Automatic English Optical Character Recognition (OCR) System Using Artificial Neural Net- works (ANNs) 2013 By Ahmed Fawzy Gad Faculty of Computers and Information (FCI) Menoufia University Egypt ahmed.fawzy@ci.menofia.edu.eg MENOUFIA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATION INFORMATION TECHNOLOGY DEPARTMENT PATTERN RECOGNITION ‫المنوفية‬ ‫جامعة‬ ‫والمعلومات‬ ‫الحاسبات‬ ‫كلية‬ ‫قسم‬‫المعلومات‬ ‫تكنولوجيا‬ ‫الرقمية‬ ‫اإلشارات‬ ‫معالجة‬ ‫المنوفية‬ ‫جامعة‬
  2. 2. OCR Using FFBP Neural Network This file contains a simple description about what I have created about how to recognize characters using feed forward back propagation neural network as a pattern recognition project when being undergraduate student at 2013. First of all, when trying to use neural network, so you for sure want to know the features to use in the process. Dataset I have choose to use the Arial font with size 20 points while being Bold to cre- ate the dataset of numbers and English letters. After capturing the image for each character, next is to make all images has the same size to make the features extracted comparable. After analyzing the images` sizes, the size that can match all the images is 20x15. Before ===========> After ===========> ===========> ===========> ===========> Features So many features can be used when trying to recognize characters. Features selected are described as follows: From every 20x15 image, find the sum of all elements in the column k and place the sum in the first element in that column. For example, in the following figure you can simply note that the first column contains the following data [1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1]' The sum of the elements of this column is 12. This value is stored at location (1,1). Continue to the whole image.
  3. 3. This process is done for all the dataset elements. The features of the first dataset image is placed in a 15x36 feature array with each feature resides a row in this array. Target The target matrix created is a 36x36 matrix. Network The network has the following details :  Two hidden layers each has 65 neurons.  All the layers are 'logsig'.  Network has epchos of 7000 and a goal of 0.
  4. 4. After training the data the network and saving it, it will be ready for working. Recognition Process 1. Extract each character in the input image independently. 1. For each character, resize its image to 20x15 pixels and then extract its fea- tures to make features extracted identical to that in the trained network. 2. Send these features to the neural network to find the best choice. 3. From the output of the simulation, you can simply determine which character was being tested. Training Network
  5. 5. MATLAB Code Image Characters Extraction function croppedChar = charExtractor(char) sig=imread(char); bSig = im2bw(sig); imwrite(bSig,'npSignal.png'); bSig = imread('npSignal.png'); info = imfinfo('npSignal.png'); %% Step 1:"Finding the beginning and the end column of each region" detectedPortionsColumns = []; %This array holds the start and end of each portion that contains data that we`ll analyze in the next step. numberOfPortions = 0; wid=1; nonOneMeanFound=0; %This flag is used to detect if a beggining or an end is found. while wid<=info.Width sigMean=mean(mean(bSig(:,wid:wid))); if sigMean~=1 & nonOneMeanFound==0 numberOfPortions=numberOfPortions+1; detectedPortionsColumns(numberOfPortions)=wid;%Holds the "beginning" of the region. nonOneMeanFound=1;%The flag is raised saying that a new region is found. end if nonOneMeanFound==1 sigMean=mean(mean(bSig(:,wid:wid))); if sigMean==1 numberOfPortions=numberOfPortions+1; detectedPortionsColumns(numberOfPortions)=wid-1;%Holds the "end" of the region. nonOneMeanFound=0;%The flag now is down saying that the end of the region is found. end end wid=wid+1;%Increment the loop variable. end %% Step 2:"Showing the cropped regions independently" clippedPortions=cell(1,numberOfPortions/2);%A cell array that contains array that represent each part. plotVar=1; findBottoms=1; while findBottoms<=numberOfPortions-1 portionBeingPro- cessed=bSig(:,detectedPortionsColumns(findBottoms):detectedPortionsColumns(findBottoms+1)); if plotVar<=numberOfPortions/2 clippedPortions{1,plotVar}=portionBeingProcessed; end plotVar=plotVar+1;
  6. 6. findBottoms=findBottoms+2; end %% Step 3:Here, I have created the testClipper.m function that is used to cut the spaces below and above the characters. detectedPortions2=cell(1,numberOfPortions/2); detectedPortions2=[]; for k=1:size(clippedPortions,2) detectedPortions2{1,k}=testClipper(clippedPortions{1,k}); end % Now, trying to find the start and end of the characters in an vertical way. detectedPortionsRows=[]; k=2; while k<=numberOfPortions detectedPortionsRows(k-1)=detectedPortions2{1,k/2}(1); detectedPortionsRows(k)=detectedPortions2{1,k/2}(2); k=k+2; end figure; plotVar=1; findBottoms=1; while findBottoms<=numberOfPortions-1 tempI- mage=bSig(detectedPortionsRows(findBottoms):detectedPortionsRows(findBottoms+1),detectedPortions Columns(findBottoms):(detectedPortionsColumns(findBottoms+1))); if plotVar<=numberOfPortions/2 croppedChar{plotVar}=tempImage; subplot(1,numberOfPortions/2,plotVar); %figure; imshow(tempImage); %export_fig 000011char -png end plotVar=plotVar+1; findBottoms=findBottoms+2; end %Now I`ll delete the pre-written images. delete('npSignal.png'); end -------------------------------------------------------- testClipper Function function detectedPortions2 = testClipper(imagePortion) imwrite(imagePortion,'clippedPortions.png');
  7. 7. imagePortion=imread('clippedPortions.png'); info=imfinfo('clippedPortions.png'); NonZeroMeanFound=0; sigMean=0; detectedPortions2=[]; for heit=1:info.Height sigMean=mean(mean(imagePortion(heit:heit,:))); if sigMean~=1&NonZeroMeanFound==0 detectedPortions2(1)=heit; NonZeroMeanFound=1; end if NonZeroMeanFound==1 sigMean=mean(mean(imagePortion(heit:heit,:))); if sigMean==1 detectedPortions2(2)=heit-1; NonZeroMeanFound=0; end end end %imshow(imagePortion(detectedPortions2(1):detectedPortions2(2),:)); delete('clippedPortions.png'); end Feature Extraction features=zeros(15,36); %m=1; for m=1:36 img=imread(['Neural',num2str(m-1),'.png']); img2=zeros(size(img,1),size(img,2)); for k=1:size(img,2) for kk=1:size(img,1) img2(1,k)=img2(1,k)+img(kk,k); end end features(:,m)=img2(1,:)'; fprintf('n%s%d%sn','Features ',m,' extracted'); end Training Network p=[12,16,15,18,16,19,12,17,16,15,19,0,16,0,0,0,15,0,0,16,0,0,0,0,14,0,14,0,18,16,5,19,19,19, 19,16 6,16,12,13,14,12,6,17,7,8,16,0,10,0,0,0,10,0,0,14,0,0,0,0,8,0,8,0,11,16,3,16,10,17,18,14
  8. 8. 4,16,10,11,12,6,4,17,3,5,10,0,6,0,0,0,4,0,0,14,0,0,0,0,4,0,6,0,8,16,2,10,3,11,14,9 2,16,9,11,12,6,2,11,2,3,8,0,4,0,0,0,6,0,0,14,16,0,6,0,6,0,8,12,5,16,1,8,7,7,13,8 2,16,9,11,12,6,2,11,2,3,8,8,10,12,8,12,10,16,0,14,16,16,8,14,10,12,12,12,6,16,14,8,12,5,13, 6 10,16,8,12,12,7,6,8,7,8,6,8,10,12,8,12,11,16,0,16,16,16,7,13,10,12,12,12,7,16,15,8,7,6,12,6 14,16,9,11,12,11,9,5,11,11,11,8,12,12,8,12,12,16,0,16,15,16,10,13,12,12,13,11,8,0,16,11,7,9 ,5,7 14,16,9,11,12,11,11,6,11,11,12,8,12,12,8,12,12,16,0,16,9,16,14,12,12,12,11,9,7,0,16,15,15,1 3,7,7 14,1,9,10,0,11,11,9,11,10,9,8,12,12,8,12,8,16,0,16,7,16,11,13,12,12,10,8,8,0,16,11,8,9,6,6 10,1,8,5,0,9,8,10,7,7,8,8,12,11,8,12,8,16,0,16,8,16,7,13,10,12,11,5,7,16,16,9,6,6,13,6 2,0,6,3,0,4,3,12,2,2,9,7,11,10,8,12,7,16,0,0,7,16,8,14,10,10,12,2,5,16,15,9,11,4,13,7 2,0,6,3,0,4,3,12,2,2,8,2,9,4,8,12,8,0,0,1,9,16,11,0,7,9,9,3,5,16,1,8,9,7,13,9 4,0,7,4,0,5,5,14,3,4,12,4,8,4,8,12,4,0,0,1,12,16,0,0,4,10,4,6,6,16,1,10,4,10,14,10 6,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0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0
  9. 9. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]; %PR = [0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1]; net = newff(minmax(p),[36 65 65 36],{'logsig','logsig','logsig','logsig'},'traingda'); net.trainParam.epochs = 7000; net.trainParam.goal = 0; net = train(net,p,t); for k=1:36 mat=sim(net,p(:,k)); fprintf('n%d%s%s',k,' => ',num2str(max(mat))); [x y]=find(mat==max(mat)) end commandwindow Testing Network detectedChars=charExtractor('im.png'); load('net.mat'); out=''; for m=1:length(detectedChars) img=detectedChars{1,m}; img=imresize(img,[20,15]); img2=zeros(size(img,1),size(img,2)); for k=1:size(img,2) for kk=1:size(img,1) img2(1,k)=img2(1,k)+img(kk,k); end end f(:,m)=img2(1,:)'; mat=sim(net,f(:,m)); [x y]=find(mat==max(mat)); out=strcat(out,OCRNeuralNetwork(x-1)); end out commandwindow NN Output to Character function outputString=OCRNeuralNetwork (templateIndex) outputString=''; switch templateIndex case 0
  10. 10. outputString=strcat(outputString,'0'); case 1 outputString=strcat(outputString,'1'); case 2 outputString=strcat(outputString,'2'); case 3 outputString=strcat(outputString,'3'); case 4 outputString=strcat(outputString,'4'); case 5 outputString=strcat(outputString,'5'); case 6 outputString=strcat(outputString,'6'); case 7 outputString=strcat(outputString,'7'); case 8 outputString=strcat(outputString,'8'); case 9 outputString=strcat(outputString,'9'); case 10 outputString=strcat(outputString,'A'); case 11 outputString=strcat(outputString,'B'); case 12 outputString=strcat(outputString,'C'); case 13 outputString=strcat(outputString,'D'); case 14 outputString=strcat(outputString,'E'); case 15 outputString=strcat(outputString,'F'); case 16 outputString=strcat(outputString,'G'); case 17 outputString=strcat(outputString,'H'); case 18 outputString=strcat(outputString,'I'); case 19 outputString=strcat(outputString,'J'); case 20 outputString=strcat(outputString,'K'); case 21 outputString=strcat(outputString,'L'); case 22 outputString=strcat(outputString,'M'); case 23 outputString=strcat(outputString,'N'); case 24
  11. 11. outputString=strcat(outputString,'O'); case 25 outputString=strcat(outputString,'P'); case 26 outputString=strcat(outputString,'Q'); case 27 outputString=strcat(outputString,'R'); case 28 outputString=strcat(outputString,'S'); case 29 outputString=strcat(outputString,'T'); case 30 outputString=strcat(outputString,'U'); case 31 outputString=strcat(outputString,'V'); case 32 outputString=strcat(outputString,'W'); case 33 outputString=strcat(outputString,'X'); case 34 outputString=strcat(outputString,'Y'); case 35 outputString=strcat(outputString,'Z'); case 36 outputString=strcat(outputString,'"Space"'); case 37 outputString=strcat(outputString,'b'); case 38 outputString=strcat(outputString,'c'); case 39 outputString=strcat(outputString,'d'); case 40 outputString=strcat(outputString,'e'); case 41 outputString=strcat(outputString,'f'); case 42 outputString=strcat(outputString,'g'); case 43 outputString=strcat(outputString,'h'); case 44 outputString=strcat(outputString,'i'); case 45 outputString=strcat(outputString,'j'); case 46 outputString=strcat(outputString,'k'); case 47 outputString=strcat(outputString,'l'); case 48
  12. 12. outputString=strcat(outputString,'m'); case 49 outputString=strcat(outputString,'n'); case 50 outputString=strcat(outputString,'o'); case 51 outputString=strcat(outputString,'p'); case 52 outputString=strcat(outputString,'q'); case 53 outputString=strcat(outputString,'r'); case 54 outputString=strcat(outputString,'s'); case 55 outputString=strcat(outputString,'t'); case 56 outputString=strcat(outputString,'u'); case 57 outputString=strcat(outputString,'v'); case 58 outputString=strcat(outputString,'w'); case 59 outputString=strcat(outputString,'x'); case 60 outputString=strcat(outputString,'y'); case 61 outputString=strcat(outputString,'z'); case 62 outputString=strcat(outputString,'SPC'); end end

×