P. 1


|Views: 122|Likes:
Published by vikky23791

More info:

Published by: vikky23791 on Oct 08, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Optical Character Recognition Using MATLAB

J.Sashank Varma#1, G.V.N.S.Varma*2, K.Vikranth Reddy#3

Electronics and Communication Engineering Department, Vignan’s Institute of Information Technology

Abstract—Optical character recognition (OCR) is used to convert the raw images into ASCII or other digital text, which reduces the file size and allows the text to be reformatted, searched, or processed by other applications. Nowadays OCR is used in many advanced fields like automatic number plate recognition, robotic vision, digitalization of books, computerize a record-keeping system in an office. Automatic number plate recognition is used by various police forces and as a method of electronic toll collection and cataloging the movements of traffic or individuals . It helps robotics by giving a way for the robot to get information from real world. The books that are digitalized can be searched for any term which helps people find books they required. In this paper we explain about how the OCR works using our algorithm in matlab. We will also explain our experimental results in this paper. Keywords— OCR, digitalization, robotic vision, traffic surveillance.

I. INTRODUCTION Optical character recognition (OCR) is used to convert the raw images into ASCII or other digital text, which reduces the file size and allows the text to be reformatted, searched, or processed by other applications. The process of optical character recognition can be broadly divided into three stages. First dividing the image into lines, next dividing letters in each line, finally converting each letter image into text. II.

A. Algorithm for OCR To perform optical character recognition there are many steps .each one is explained below. 1) Input image: The input image can be either RGB or gray scale .if RGB is given as input convert the image into grey scale image. We convert image into grey scale for better processing. 2) Converting to binary image: The grey scale image has to be converted to binary image for the processing to take place. In binary image each cell value is either 0 or 1. 3) Separating first line from remaining lines: The first line separated from the remaining lines for processing each line individually. 4) Separate letters in each line: All the letters in first line are separate for comparison with database

imgn=fl.bmp').bmp'). six=imread('letters_numbers\6.txt as file for write fid = fopen('text.eight=imread('letter s_numbers\8. E=imread('letters_numbers\E. % Resize letter (same size of template) img_r=imresize(n1.bmp'). 24 24 24 24 24 24 24 .bmp'). C=imread('letters_numbers\C.bmp').bmp').H=imread('letters_nu mbers\H.c] = find(L==n). zero=imread('letters_numbers\0..threshold). two=imread('letters_numbers\2.bmp').min(c):max(c)).bmp'). 7) Looping level: Here the program checks whether there are any remaining lines.T=imread('letters_num bers\T. five=imread('letters_numbers\5.V=imread('letters_nu mbers\V.L=imread('letters_num bers\L.bmp'). %Number one=imread('letters_numbers\1.bmp').bmp').%Write 'word' in text file (upper) % Clear 'word' variable word=[ ].bmp'). If there are any remaining lines then the process goes to stage 3.Else to stage 8.'templates') .42. %Opens text.bmp').. for n=1:Ne [r..'%s\n'.bmp').bmp')..bmp'). %*-*-*-*-*-*-*-*-*-*-*letter=[A B C D E F G H I J K L M.J=imread('letters_numbe rs\J.bmp').D=imread('letters_num bers\D.bmp').bmp').four=imread('letters _numbers\4. breaks the loop if isempty(re) %See variable 're' in Fcn 'lines' break end end fclose(fid).bmp').N=imread('letters_nu mbers\N.bmp'). M=imread('letters_numbers\M.bmp'). % Convert to BW threshold = graythresh(imagen). %Storage matrix word from image word=[ ].bmp').2).bmp'). 'wt'). Q=imread('letters_numbers\Q.num_letras). % Extract letter n1=imgn(min(r):max(r).B=imread('letters_num bers\B. W=imread('letters_numbers\W. nine=imread('letters_numbers\9.X=imread('letters_nu mbers\X.word). 24 24 24 24 24 24 24 . save ('templates'. Y=imread('letters_numbers\Y. K=imread('letters_numbers\K. I=imread('letters_numbers\I.bmp').bmp').bmp').F=imread('letters_num bers\F. 8) Saving the text file: Finally after all the letters are entered and there are no remaining lines. clear all %CREATE TEMPLATES %Letter A=imread('letters_numbers\A. 24 24 24 24 24 24 24 24]).bmp').bmp').bmp'). U=imread('letters_numbers\U. while 1 %Fcn 'lines' separate lines in text [fl re]=lines(re).[42 24]). N O P Q R S T U V W X Y Z].bmp')... six seven eight nine zero].bmp'). % Load templates load templates global templates % Compute the number of letters in template file num_letras=size(templates.5) Converting each letter image to text: All the letters images are compared with the database images and the most likely alphanumerical is entered as text. 6) Removing first line from processing image: As the first line is processed it is removed from the processing image. 24 24 24 24 24 24 24 .[24 24 24 24 24 24 24 . III. %-----------------------------------------------------------------% Call fcn to convert image to text letter=read_letter(img_r. O=imread('letters_numbers\O. character=[letter number].R=imread('letters_num bers\R. imagen =~im2bw(imagen.bmp'). SOURCE CODE % OCR (Optical Character Recognition). %*When the sentences finish.. %----------------------------------------------------------------% Label and count connected components [L Ne] = bwlabel(imgn). seven=imread('letters_numbers\7. re=imagen.bmp'). % Read image imagen=imread('TEST_8.Z=imread('letters_num bers\Z.bmp'). templates=mat2cell(character.bmp'). S=imread('letters_numbers\S. end fprintf(fid. number=[one two three four five.P=imread('letters_num bers\P.. then the text file is saved.. G=imread('letters_numbers\G.... % Letter concatenation word=[word letter].txt'. three=imread('letters_numbers\3.jpg').

elseif vd==15 letter='O'. elseif vd==18 letter='R'. num_filas=size(im_texto. comp=[comp sem]. elseif vd==29 letter='3'. :). %*-*-*-*-*-*-*-*-*-*-*-*-*if vd==1 letter='A'. end end function img_out=clip(img_in) [f c]=find(img_in). end . re=clip(rm).% Remain line matrix fl = clip(nm). elseif vd==31 letter='5'. z=im_texto imwrite(z. elseif vd==4 letter='D'. elseif vd==23 letter='W'. elseif vd==35 letter='9'.1). break else fl=im_texto. end vd=find(comp==max(comp)). elseif vd==13 letter='M'. elseif vd==24 letter='X'. elseif vd==34 letter='8'. elseif vd==7 letter='G'. %*-*-*-*-* elseif vd==27 letter='1'. elseif vd==5 letter='E'.imagn). elseif vd==12 letter='L'. elseif vd==19 letter='S'.min(c):max(c)). elseif vd==11 letter='K'. elseif vd==3 letter='C'. elseif vd==30 letter='4'. elseif vd==6 letter='F'. :). elseif vd==32 letter='6'. elseif vd==9 letter='I'. elseif vd==20 letter='T'. % First line matrix rm=im_texto(s:end. elseif vd==2 letter='B'. elseif vd==17 letter='Q'. elseif vd==14 letter='N'.'binary clip'. else letter='0'. elseif vd==8 letter='H'. elseif vd==16 letter='P'. elseif vd==22 letter='V'.:))==0 nm=im_texto(1:s-1. img_out=img_in(min(f):max(f). for n=1:num_letras sem=corr2(templates{1. for s=1:num_filas if sum(im_texto(s. elseif vd==28 letter='2'.n}.num_letras) % Computes the correlation between template and input image % and its output is a string containing the letter.'jpg'). % Size of 'imagn' must be 42 x 24 pixels global templates comp=[ ]. elseif vd==10 letter='J'.%Crops image function letter=read_letter(imagn. re=[ ].clear all function [fl re]=lines(im_texto) im_texto=clip(im_texto).%Only one line. elseif vd==25 letter='Y'. elseif vd==33 letter='7'. elseif vd==21 letter='U'. elseif vd==26 letter='Z'.

The various stages in the the processing are illustrated below. 6 Fig. 9 The remaining line is divided into separate letters as shown in Fig. 10 . 5 Fig. 5 Now by comparing each letter with our database we can determine which letter it is. 7 \ Fig. 3 Fig. 2 Fig. 6 Now again divide the lines as shown in Fig. We took an image as shown in Fig. 10 Fig. Next the remaining lines are as shown in Fig. 3 input as binary image Fig. 7 Now divide the first line into separate letters as shown in Fig.IV. EXPERIMENTAL RESULTS We have taken a test image and applied our algorithm to it in matlab. 8 Now we have separated the first line from remaining lines and the resulting images are shown in Fig. 1 input image Next we converted it to binary image as shown in Fig. 4 Fig. 4 Now the first line is divided into separate letters as shown in Fig. 8 The remaining line is shown in Fig.

Till now the algorithm is developed to use with only capital letters. 11 Fig. But by increasing the database we can also identify small letters and special characters. By further developing the algorithm we can also extract tables.mathworks. lines and many other things from the image.Now by comparing the separate letters with database we can find out the letters. The result is shown in a text file as shown in Fig.org/wiki/Book_scanning . By showing the results results we have shown the working of a OCR.wikipedia. REFERENCES [1] [2] [3] http://en. CONCLUSIONS In this paper we have discussed the algorithm and implementation of optical character recognition in matlab. We also create font specific optical character recognition and by further developing the algorithm we can create hand writing recognition system and hand writer recognition systems. We finally conclude that OCR has a lot of advantages and the working is illustrated above.com/ http://en.org/wiki/Optical_character_recognition http://www. 11 IV.wikipedia.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->