You are on page 1of 5

Optical Character Recognition

using MATLAB

Department of Electrical Engineering


Indian Institute of Technology, Kanpur

EE301: Digital Signal Processing


Spring, 2011

Instructor: Dr. Naren Naik


Submitted by,
N Manoj Kumar, Y8310
Raghuram K, Y8384
Introduction: What is OCR?

The goal of Optical Character Recognition (OCR) is to classify optical


patterns (often contained in a digital image) corresponding to alphanumeric or other
characters. The process of OCR involves several steps including segmentation, feature
extraction, and classification. Each of these steps is a field unto itself, and is described
briefly here in the context of a MATLAB implementation of OCR.

Example of OCR:

Optical
Character
Recognition
Y8310
Y8384

OCR Pre-processing:
These are the pre-processing steps often performed in OCR.

Binarization Usually presented with a grayscale image, binarization is then simply


a matter of choosing a threshold value.

Morphological Operators Remove isolated specks and holes in characters. Can use
certain morphological operators such a bwareopen etc.

Segmentation This is the most important part of the whole process. Check
connectivity of shapes, label, and isolate. Can use Matlabs bwlabel and regionprops
functions. Difficulties with characters that arent connected, e.g. the letter i, a
semicolon, or a colon (; or :). An alternate way is extracting lines and then characters
in each of the lines by detection of boundary 1-pixels and the cropping them. This
way, the problem with unconnected letters like i, ;, : etc., can be taken care of.
OCR Feature extraction:

After obtaining the individual characters, we have to find out which one
corresponds to what. There are several ways of doing this. The criteria used for
evaluating the accuracy of these ways are the following.
Robustness.
1) Noise.
Sensitivity to disconnected line segments, bumps, gaps, filled loops etc.
2) Distortions.
Sensitivity to local variations like rounded corners, improper protrusions,
dilations and shrinkage.
3) Style variation.
Sensitivity to variation in style like the use of different shapes to represent the
same character or the use of serifs, slants etc.
4) Translation.
Sensitivity to movement of the whole character or its components.
5) Rotation.
Sensitivity to change in orientation of the characters.

Practical use.
1) Speed of recognition.
2) Complexity of implementation.
3) Independence.
The need of supplementary techniques.

In our implementation, we used the most primitive but practical way as our means of
feature extraction i.e. Template Matching.

Template-matching and correlation techniques:-


These techniques are different from the others in that no features are actually
extracted. Instead the matrix containing the image of the input character is directly
matched with a set of prototype characters representing each possible class. The
distance between the pattern and each prototype (Template) is computed, and the
class of the prototype giving the best match is assigned to the pattern. The technique
is simple and easy to implement in hardware and has been used in many commercial
OCR machines. However, this technique is sensitive to noise and style variations and
has no way of handling rotated characters.

Algorithm used in the code:-

Pre processing and Segmentation:


The first step of pre processing is implemented through main_code.m and
process_image.m
After doing segmentation as described above through extract_lines.m and
extract_characters.m, we do the training

Training:
We make templates of each character (images of size 50 X 30 containing
individual characters). Then, we store them in a cell array. This is done in
create_templates.m

Recognition:
After obtaining the regions of image with characters, we resize each of them
into a 50 X 30 image to match the size of templates we have created. Picking each of
the character images, we correlate it with each of the templates we have and store the
values in a cell. The template which gives the maximum correlation coefficient for an
individual character image should give us the character in the image. This is
implemented using the M-file read_character.m.

Correlation of two 2-D images using corr2 function of MATLAB:

Drawbacks of the method used:


Template matching and correlation as a very sophisticated and highly practical
way of character recognition method. Nevertheless, using only correlation function as
a way of implementing matched filtering to recognize the characters makes this
method highly font sensitive and style sensitive.
Example:
(1) Confusion between letters B,8 and 6,G and 0,O etc.
(2) Lack of accuracy in differentiating uppercase and lowercase letters in case of
O,o; C,c; Z,z; X,x; V,v etc.
(3) If the image has characters in a different font, the code may fail to detect some
characters properly (The errors can be very huge depending upon the
differences in the styles of fonts).
Suggestions for further improvement:
To improve the accuracy,
Improve the preprocessing by using adaptive thresholding before binarizing
Use better morphology such as erosion, dilation and more effective noise
removal methods
Use advanced feature extraction techniques such as Fourier Descriptors,
higher order statistical moments, neural networks, transformations such as
Hough transform etc.

Although the above suggested ways may give us OCR with better accuracy, the have
their drawbacks

Difficulty in implementation
Requirement of more time for processing thereby making them less practical
Even after all this, some of them require additional context based error
detection such as use of dictionaries, syntax and adaptive techniques for their
performance

Conclusion:
The objective o segment and recognize characters in image have been
achieved. We used only Template matching and correlation as our recognition
process. So, the accuracy may not be very good. But, a very good way is suggested
below based on experimental results as given in a paper.
After several experiments been done to find the best method to recognize the
characters with highest accuracy and considerable amount of time, the best way is by
using templates correlations as main recognition method with Fourier Descriptor and
several heuristic approach as filters. Experiments have found that this methods
recognition accuracy is 98.46%.

Sources:
(1) Line Eikvil Optical Character Recognition, December 1993 .
(2) Badruz Nasrin Bin Basri Text Detection and Character recognition from
images. (ppt)
(3) Digital Image Processing Using MATLAB by Gonzalez and Woods.

You might also like