Professional Documents
Culture Documents
Introduction:
PATTERN RECOGNITION
Pattern Recognition has attracted the attention of researchers in last few decades as a machine
learning approach due to its wide spread application areas. The application area includes
medicine, communications, automations, military intelligence, data mining, bioinformatics,
document classification, speech recognition, business and many others.
Automatic (machine) recognition, description, classification, and grouping of patterns are
important problems in a variety of engineering and scientific disciplines such as biology,
psychology, medicine, marketing, computer vision, artificial intelligence, and remote sensing.
But what is a pattern?
PATTERN : Pattern is a set of objects or phenomena or concepts where the elements of the set
are similar to one another in certain ways/aspects. The Pattern are described by certain quantities,
qualities, behaviors, notable features and so on.
Example : Humans, insects, Animals, clouds etc.
Cloud patterns
Pattern + Recognition
Humans have a pattern which is different from the pattern of animals. Each individuals has a
pattern which is different from the patterns of others.
There are numerous number applications of pattern recognition techniques which are shown in
below table.
The design of a pattern recognition system essentially involves the following three aspects:
1) data acquisition and preprocessing,
2) data representation, and
3) decision making.
The four best known approaches for pattern recognition are: 1) template matching, 2) statistical
classification, 3) syntactic or structural matching, and 4) neural networks.
So here the task is to recognize the face using different pattern recognition techniques
which will be described in the sections to follow.
What is Pattern Recognition?
Pattern Recognition is the study of how machines can observe the environment,
learn to distinguish patterns of interest from their background, and
make sound and reasonable decisions about the categories of the patterns.
Classification in PR
A class is a set of objects having some important properties in common
A feature extractor is a program that inputs the data (image) and extracts features that can be
used in classification.
A classifier is a program that inputs the feature vector and assigns it to one of a set of
designated classes or to the reject class.
1)
Model construction: describing a set of predetermined classes
Each tuple/sample is assumed to belong to a predefined class, as determined by the class label
attribute
The set of tuples used for model construction: training set
The model is represented as classification rules, decision trees, or mathematical formulae
The four best known approaches for pattern recognition are: 1) template matching, 2) statistical
classification, 3) syntactic or structural matching, and 4) neural networks.
The detailed description of these methods are described in the below sections.
1.Template Matching:
One of the simplest and earliest approaches to pattern recognition is based on template matching.
Matching is a generic operation in pattern recognition which is used to determine the similarity
between two entities (points, curves, or shapes) of the same type.
Template Matching techniques compare portions of images against one another.
Sample image may be used to recognize similar objects in source image.
If standard deviation of the template image compared to the source image is small enough,
template matching may be used.
Templates are most often used to identify printed characters, numbers, and other small, simple
objects.
General Idea of Template Matching
create a small template image of the feature we want to detect
center the template image over pixel( i, j) in a target image
calculate the pixel differences between the template image and the pixels centered at ( i, j )
if the distance is small, the template is similar to the window centered at ( i , j)
if the distance is large, the template is dissimilar
repeat for all pixels
the minimum distance is the best match
this is known as template matching
Face Detection using Template matching:
A window slides across image and evaluate a face model at every location.Then above
procedure is followed to detect face.
Normalized Template-Matching
We can normalize each image patch, and the template in various ways before performing the
match
e.g., subtract the mean from both the template and the image patch
effect?
removes any additive lighting effect
Correlation
Given an image, we want to find all places in the image which contain a subimage, also called a
template.
Very useful for answering where is the x in this picture?
Method
The matching process moves the template image to all possible positions in a larger source image
and computes a numerical index that indicates how well the template matches the image in that
position.
Match is done on a pixel-by-pixel basis. The matching process moves the template image to all
possible positions in a larger source image and computes a numerical index that indicates how
well the template matches the image in that position. Match is done on a pixel-by-pixel basis.
Correlation
Just the dot product between the template and a
neighborhood in the image.
Idea: high correlation when the template matches.
Problem: always high correlation when matching with a
plain bright region
Solution: Normalize the template and each region by
subtracting eachs mean from itself before taking dot
product
Correlation is Computation Intensive
Euclidean Distance
Let I be a gray level image
and g be a gray-value template of size nxm.
The statistical Vs structural approaches: The goal is to discriminate between the square and the
triangle. A statistical approach extracts quantitative features which are assembled into feature
vectors for classification.
A structural approach extracts morphological features and their interrelationships,
encoding them in relational graphs;
Structural pattern recognition Describe complicated objects in terms of simple primitives and
structural relationships.
It helps in Decision-making when features are non-numeric or structural
Final step
Compare the chain code strings of the 2 sets of boundary points.
Features are chosen in such a way that different patterns occupy non-overlapping feature space.
It recognizes the probabilistic nature both of the information we seek to process, and of the form
in which we should express it [2]. It works well when the selected features lead to feature spaces
which cluster in a recognizable manner, i.e. there is proper interclass distance. After analyzing
the probability distribution of a pattern belonging to a class, decision boundary is determined [3],
[4]. Here patterns are projected to pre-processing operations to make them suitable for training
purposes. Features are selected upon analyzing training patterns. System learns and adapts itself
for unknown patterns as shown in Fig. 1.Test patterns are applied to check suitability of system
to recognize patterns. Feature
measurement is done while testing, then these feature values is presented to learned system and
in this way classification is performed. When conditional probability density distribution is
known, parametric classification schemes are used otherwise non parametric classification
scheme need to be used. Various decision rules are there to determine decision boundary like,
Bayes Decision Rule, Optimal Bayes Decision Rule, The Maximum Likelihood Rule, NeymanPearson rule and MAP rule. As feature spaces are partitioned, system becomes noise insensitive,
therefore in case of noisy patterns. The choice of statistical model is a good solution. Depending
upon whether the method opted is supervised or unsupervised statistical technique can be
categorized as: Discriminant Analysis and Principal Component Analysis [1].
related to Factor Analysis [11]. Kernel PCA is a solution for nonlinear feature extraction [12],
[13].Other nonlinear feature extraction techniques are Multidimensional scaling (MDS) and
Kohonen feature Map [14]. Application areas of PCA include graphically unreliable patterns.
Discriminant Analysis is more efficient as compared to PCA, in terms of accuracy and time
elapsed [15].
Neural networks are the massively parallel structures composed of neuron like subunits [29].
Neural networks provide efficient result in the field of classification. Its property of changing its
weight iteratively and learning [10], [30], give it an edge over other techniques for recognition
process.
'tansig'-'tansig' combination of activation functions for neurons of hidden layer and output layer
opted rather than opting for other combinations [36].
Regression Analysis: A statistical procedure used to find relationships among a set of variables
In regression analysis, there is a dependent variable, which is the one you are trying to explain,
and one or more independent variables that are related to it.
You can express the relationship as a linear equation, such as:
y = a + bx
TYPICAL APPLICATIONS
Sorting Fish: incoming fish are sorted according to species using optical sensing (sea bass or
salmon?)
Problem Analysis:
set up a camera and take some sample images to extract features
Consider features such as length, lightness, width, number and shape of fins, position of
mouth, etc.
Sorting incoming Fish on a conveyor according to species using optical sensing
Problem Analysis
Set up a camera and take some sample images to extract features
Length
Lightness
Width
Number and shape of fins
Position of the mouth, etc
This is the set of all suggested features to explore for use in our classifier!
Preprocessing
Use a segmentation operation to isolate fishes from one another and from the background
Information from a single fish is sent to a feature extractor whose purpose is to reduce the data
by measuring certain features
We might add other features that are not correlated with the ones we already have. A precaution
should be taken not to reduce the performance by adding noisy features
Ideally, the best decision boundary should be the one which provides an optimal performance
such as in the following figure:
However, our satisfaction is premature because the central aim of designing a classifier is to
correctly classify novel input
Issue of generalization!
Application:
Face Detection:
Face Detection and Tracking Using CAMShift and Viola Jones algorithm
This example shows how to automatically detect and track a face.
Introduction
Object detection and tracking are important in many computer vision applications including
activity recognition, automotive safety, and surveillance. In this example, you will develop a
simple face tracking system by dividing the tracking problem into three separate problems:
1.
2.
3.
FACE RECOGNITION:
Face recognition is the recognizing a special face from a set of different faces. Face has a
significant role in human beings communications where, each person along with his/her feelings
mainly is distinguished by his/her face image. One can easily find out that one of the main
problems in machine-human being interactions is the face recognition problem. A human face is
a complex object with features varying over time. So a robust face recognition system must
operate under a variety of conditions. Face recognition has been undoubtedly one of the major
topics in the image processing and pattern recognition in the last decade due to the new interests
in, security, smart environments, video indexing and access control. Existing and future
applications of face recognition are many [1]. We divide these applications into two main
categories of governmental and commercial uses. Rapid progression
through customs by using face as a live passport in immigration, comparison of surveillance
images against an image database of known terrorists and other unwanted people in
security/counterterrorism, and Verifying identity of people found unconscious, dead or
individuals refusing to identify themselves in hospital are examples of governmental uses.
Withdrawing cash from an automated teller machine (ATM) without cards or pin numbers in
banking and access control of home and office in premises access control are some examples of
commercial uses of face recognition systems which demonstrate the importance of these
systems.
A new Hidden Markov Model (HMM)-based face recognition system is designed. As a novel
point despite of five-state HMM used in pervious researches, we add two new face regions,
eyebrows and chin, to the model. As another novel point, we used a small number of quantized
Singular Values Decomposition (SVD) coefficients as features describing blocks of face images.
This makes the system very fast. The system has been evaluated on the Olivetti Research
Laboratory (ORL) face database. In order to additional reduction in computational complexity
and memory consumption the images are resized to 6464 jpeg format. Before anything, an
order-statistic filter is used as a preprocessing operation. Then a top-down sequence of
overlapping sub-image blocks is considered. Using quantized SVD coefficients of these blocks,
each face is considered as a numerical sequence that can be easily modeled by HMM. The
system has been examined on 400 face images of the Olivetti Research Laboratory (ORL) face
database. The experiments showed a recognition rate of 99%, using half of the images for
training.
Mainmenu.m
% Face Recognition System
% Original Paper :
% H. Miar-Naimi and P. Davari A New Fast and Efficient HMM-Based
% Face Recognition System Using a 7-State HMM Along With SVD Coefficients
clear all;
close all;
clc;
if (exist('DATABASE.mat','file'))
load DATABASE.mat;
end
while (1==1)
choice=menu('Face Recognition',...
'Generate Database',...
'Calculate Recognition Rate',...
'Recognize from Image',...
'Recognize from Webcam',...
'Exit');
if (choice ==1)
if (~exist('DATABASE.mat','file'))
[myDatabase,minmax] = gendata();
else
pause(0.1);
choice2 = questdlg('Generating a new database will remove any previous trained
database. Are you sure?', ...
'Warning...',...
'Yes', ...
'No','No');
switch choice2
case 'Yes'
pause(0.1);
[myDatabase minmax] = gendata();
case 'No'
end
end
end
if (choice == 2)
if (~exist('myDatabase','var'))
fprintf('Please generate database first!\n');
else
recognition_rate = testsys(myDatabase,minmax);
end
end
if (choice == 3)
if (~exist('myDatabase','var'))
fprintf('Please generate database first!\n');
else
pause(0.1);
[file_name file_path] = uigetfile ({'*.pgm';'*.jpg';'*.png'});
if file_path ~= 0
filename = [file_path,file_name];
facerec (filename,myDatabase,minmax);
end
end
end
if (choice == 4)
I = getcam();
if (~isempty(I))
filename = ['./',num2str(floor(rand()*10)+1),'.pgm'];
imwrite(I,filename);
if (exist('myDatabase','var'))
facerec (filename,myDatabase,minmax);
end
end
end
if (choice == 5)
clear choice choice2
return;
end
end
facerec.m
% Face Recognition System
function [person_index,maxlogpseq] = facerec(filename,myDatabase,minmax)
I = imread(filename);
try
I = rgb2gray(I);
end
I = imresize(I,[56 46]);
I = ordfilt2(I,1,true(3));
min_coeffs = minmax(1,:);
max_coeffs = minmax(2,:);
delta_coeffs = minmax(3,:);
seq = zeros(1,52);
for blk_begin=1:52
blk = I(blk_begin:blk_begin+4,:);
[U,S,V] = svd(double(blk));
blk_coeffs = [U(1,1) S(1,1) S(2,2)];
blk_coeffs = max([blk_coeffs;min_coeffs]);
blk_coeffs = min([blk_coeffs;max_coeffs]);
qt = floor((blk_coeffs-min_coeffs)./delta_coeffs);
label = qt(1)*7*10+qt(2)*7+qt(3)+1;
seq(1,blk_begin) = label;
end
number_of_persons_in_database = size(myDatabase,2);
results = zeros(1,number_of_persons_in_database);
for i=1:number_of_persons_in_database
TRANS = myDatabase{6,i}{1,1};
EMIS = myDatabase{6,i}{1,2};
[ignore,logpseq] = hmmdecode(seq,TRANS,EMIS);
P=exp(logpseq);
results(1,i) = P;
end
[maxlogpseq,person_index] = max(results);
fprintf('\n');
end
end
delta = (max_coeffs-min_coeffs)./([18 10 7]-eps);
minmax = [min_coeffs;max_coeffs;delta];
for person_index=1:40
for image_index=1:5
for block_index=1:52
blk_coeffs = myDatabase{2,person_index}{block_index,image_index};
min_coeffs = minmax(1,:);
delta_coeffs = minmax(3,:);
qt = floor((blk_coeffs-min_coeffs)./delta_coeffs);
myDatabase{3,person_index}{block_index,image_index} = qt;
label = qt(1)*10*7+qt(2)*7+qt(3)+1;
myDatabase{4,person_index}{block_index,image_index} = label;
end
myDatabase{5,person_index}{1,image_index} = cell2mat(myDatabase{4,person_index}
(:,image_index));
end
end
TRGUESS = ones(7,7) * eps;
TRGUESS(7,7) = 1;
for r=1:6
TRGUESS(r,r) = 0.6;
TRGUESS(r,r+1) = 0.4;
end
EMITGUESS = (1/1260)*ones(7,1260);
fprintf('\nTraining ...\n');
for person_index=1:40
fprintf([myDatabase{1,person_index},' ']);
seqmat = cell2mat(myDatabase{5,person_index})';
[ESTTR,ESTEMIT]=hmmtrain(seqmat,TRGUESS,EMITGUESS,'Tolerance',.01,'Maxiterations',
10,'Algorithm', 'BaumWelch');
ESTTR = max(ESTTR,eps);
ESTEMIT = max(ESTEMIT,eps);
myDatabase{6,person_index}{1,1} = ESTTR;
myDatabase{6,person_index}{1,2} = ESTEMIT;
if (mod(person_index,10)==0)
fprintf('\n');
end
end
fprintf('done.\n');
save DATABASE myDatabase minmax
testsys.m
% Face Recognition System
function recognition_rate = testsys(myDatabase,minmax)
ufft = [2 3 4 7 9];
total = 0;
recognition_rate = 0;
fprintf('Please Wait...\n');
data_folder_contents = dir ('./data');
number_of_folders_in_data_folder = size(data_folder_contents,1);
person_index = 0;
for person=1:number_of_folders_in_data_folder
if (strcmp(data_folder_contents(person,1).name,'.') || ...
strcmp(data_folder_contents(person,1).name,'..') || ...
(data_folder_contents(person,1).isdir == 0))
continue;
end
person_index = person_index+1;
person_name = data_folder_contents(person,1).name;
fprintf([person_name,'\n']);
person_folder_contents = dir(['./data/',person_name,'/*.pgm']);
for face_index=1:size(ufft,2)
total = total + 1;
filename = ['./data/',person_name,'/',person_folder_contents(ufft(face_index),1).name];
answer_person_index = facerec(filename,myDatabase,minmax);
if (answer_person_index == person_index)
recognition_rate = recognition_rate + 1;
end
end
end
recognition_rate = recognition_rate/total*100;
fprintf(['\nRecognition Rate is ',num2str(recognition_rate),'%% for a total of ',num2str(total),'
unseen faces.\n']);
Command Output:
Clicked Yes button,we load the faces and train the system.
Loading Faces ...
s1 s10 s11 s12 s13 s14 s15 s16 s17 s18
s19 s2 s20 s21 s22 s23 s24 s25 s26 s27
s28 s29 s3 s30 s31 s32 s33 s34 s35 s36
s37 s38 s39 s4 s40 s5 s6 s7 s8 s9
Training ...
s1 s10 s11 s12 s13 s14 s15 s16 s17 s18
s19 s2 s20 s21 s22 s23 s24 s25 s26 s27
s28 s29 s3 s30 s31 s32 s33
(Recognized Image)
For unknown image output is as below.
word=[word letter];
end
%fprintf(fid,'%s\n',lower(word));%Write 'word' in text file (lower)
fprintf(fid,'%s\n',word);%Write 'word' in text file (upper)
% Clear 'word' variable
word=[ ];
%*When the sentences finish, breaks the loop
if isempty(re) %See variable 're' in Fcn 'lines'
break
end
end
fclose(fid);
%Open 'text.txt' file
winopen('text.txt')
clear all
read_letter.m
function letter=read_letter(imagn,num_letras)
% Computes the correlation between template and input image
% and its output is a string containing the letter.
% Size of 'imagn' must be 42 x 24 pixels
% Example:
% imagn=imread('D.bmp');
% letter=read_letter(imagn)
global templates
comp=[ ];
for n=1:num_letras
sem=corr2(templates{1,n},imagn);
comp=[comp sem];
end
vd=find(comp==max(comp));
%*-*-*-*-*-*-*-*-*-*-*-*-*if vd==1
letter='A';
elseif vd==2
letter='B';
elseif vd==3
letter='C';
elseif vd==4
letter='D';
elseif vd==5
letter='E';
elseif vd==6
letter='F';
elseif vd==7
letter='G';
elseif vd==8
letter='H';
elseif vd==9
letter='I';
elseif vd==10
letter='J';
elseif vd==11
letter='K';
elseif vd==12
letter='L';
elseif vd==13
letter='M';
elseif vd==14
letter='N';
elseif vd==15
letter='O';
elseif vd==16
letter='P';
elseif vd==17
letter='Q';
elseif vd==18
letter='R';
elseif vd==19
letter='S';
elseif vd==20
letter='T';
elseif vd==21
letter='U';
elseif vd==22
letter='V';
elseif vd==23
letter='W';
elseif vd==24
letter='X';
elseif vd==25
letter='Y';
elseif vd==26
letter='Z';
%*-*-*-*-*
elseif vd==27
letter='1';
elseif vd==28
letter='2';
elseif vd==29
letter='3';
elseif vd==30
letter='4';
elseif vd==31
letter='5';
elseif vd==32
letter='6';
elseif vd==33
letter='7';
elseif vd==34
letter='8';
elseif vd==35
letter='9';
else
letter='0';
end
lines.m
function [fl re]=lines(im_texto)
% Divide text in lines
% im_texto->input image; fl->first line; re->remain line
% Example:
% im_texto=imread('TEST_3.jpg');
% [fl re]=lines(im_texto);
% subplot(3,1,1);imshow(im_texto);title('INPUT IMAGE')
% subplot(3,1,2);imshow(fl);title('FIRST LINE')
% subplot(3,1,3);imshow(re);title('REMAIN LINES')
im_texto=clip(im_texto);
num_filas=size(im_texto,1);
for s=1:num_filas
if sum(im_texto(s,:))==0
nm=im_texto(1:s-1, :); % First line matrix
rm=im_texto(s:end, :);% Remain line matrix
fl = clip(nm);
re=clip(rm);
%*-*-*Uncomment lines below to see the result*-*-*-*%
subplot(2,1,1);imshow(fl);
%
subplot(2,1,2);imshow(re);
break
else
fl=im_texto;%Only one line.
re=[ ];
end
end
function img_out=clip(img_in)
[f c]=find(img_in);
img_out=img_in(min(f):max(f),min(c):max(c));%Crops image
create_template.m
%CREATE TEMPLATES
%Letter
A=imread('letters_numbers\A.bmp');B=imread('letters_numbers\B.bmp');
C=imread('letters_numbers\C.bmp');D=imread('letters_numbers\D.bmp');
E=imread('letters_numbers\E.bmp');F=imread('letters_numbers\F.bmp');
G=imread('letters_numbers\G.bmp');H=imread('letters_numbers\H.bmp');
I=imread('letters_numbers\I.bmp');J=imread('letters_numbers\J.bmp');
K=imread('letters_numbers\K.bmp');L=imread('letters_numbers\L.bmp');
M=imread('letters_numbers\M.bmp');N=imread('letters_numbers\N.bmp');
O=imread('letters_numbers\O.bmp');P=imread('letters_numbers\P.bmp');
Q=imread('letters_numbers\Q.bmp');R=imread('letters_numbers\R.bmp');
S=imread('letters_numbers\S.bmp');T=imread('letters_numbers\T.bmp');
U=imread('letters_numbers\U.bmp');V=imread('letters_numbers\V.bmp');
W=imread('letters_numbers\W.bmp');X=imread('letters_numbers\X.bmp');
Y=imread('letters_numbers\Y.bmp');Z=imread('letters_numbers\Z.bmp');
%Number
one=imread('letters_numbers\1.bmp'); two=imread('letters_numbers\2.bmp');
three=imread('letters_numbers\3.bmp');four=imread('letters_numbers\4.bmp');
five=imread('letters_numbers\5.bmp'); six=imread('letters_numbers\6.bmp');
seven=imread('letters_numbers\7.bmp');eight=imread('letters_numbers\8.bmp');
nine=imread('letters_numbers\9.bmp'); zero=imread('letters_numbers\0.bmp');
%*-*-*-*-*-*-*-*-*-*-*letter=[A B C D E F G H I J K L M...
N O P Q R S T U V W X Y Z];
number=[one two three four five...
six seven eight nine zero];
character=[letter number];
templates=mat2cell(character,42,[24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24]);
save ('templates','templates')
clear all
Test2.jpg
Text Content
ESTA67
ES767
UNA4567
PRUEBA5887
Conclusion:
A comparative view of all the models of pattern recognition has been shown which depicts that
for various domains in this areas different models or combination of models can be used. In case
of noisy patterns, choice of statistical model is a good solution. Practical importance of structural
model depends upon recognition of simple pattern primitives and their relationships represented
by description language. As compared to statistical pattern recognition, structural pattern
recognition is a newer area of research. For complex patterns and applications utilizing large
number of pattern classes, it is beneficial to describe each pattern in terms of its components. A
wise decision regarding the selection of Pattern grammar influences computations efficiency of
recognition system. Pattern primitives and pattern grammar to be utilized depends upon the
application requirements. Low dependence of neural networks on prior knowledge and
availability of efficient learning algorithms have made the neural networks famous in the field of
Patten Recognition. Although neural networks and statistical pattern recognition models have
different principles most of the neural networks are similar to statistical pattern recognition
modelsAs each model has its own pros and cons, therefore to enhance system performance for
complex applications it is beneficial to append two or more recognition models at various stages
of recognition process.
References:
1. H. Miar-Naimi and P. Davari A New Fast and Efficient HMM-Based Face Recognition
System Using a 7-State HMM Along With SVD Coefficient
2.
http://in.mathworks.com/
3. [1]. K.S. Fu, A Step towards Unification of Syntactic and Statistical Pattern Recognition,
IEEE Trans. Pattern Analysis and Machine Intelligence, vol. 5, no. 2, pp. 200-205, Mar. 1983.
[2]. Amin Fazel and Shantnu Chakrabartty, An Overview of Statistical Pattern Recognition
Techniques for Speaker Verification, IEEE circuits and systems, pp. 61-81, magazine 2 nd
quarter 2011. [3]. L. Devroye, L. Gyorfi, and G. Lugosi, "A Probabilistic Theory of Pattern
Recognition." Berlin: Springer-Verlag, 1996. [4]. R.O.Duda and P.E.Hart, Pattern Classification
and Scene Analysis, New York: John Wiley & sons, 1973. [5]. W.W.Cooley and P.R. Lohnes,"
Multivariate Data Analysis."New York: Wiley, 1971. [6]. R.Fisher, "The Use of Multiple
Measurements in Taxonomic Problems," Ann. Eugenics, vol. 7, no. 2, pp. 179-188,1936. [7].
M.M. Tatsouka, "Multivariate Analysis."New York: Wiley, 1971