Anda di halaman 1dari 7

Chapter: 2

Eigenspace Projection
Eigenspace is calculated by identifying by the eigenvectors of the covariance matrix derived
from a set of training images. The eigenvectors corresponding to non-zero eigenvalues of the
covariance matrix from an orthonormal basis that rotates and/or reflects the images in the N-
dimensional space. pecifically! each image is stored in a vector of size N.
[ ]
n
i
x x x X . .
2 "
=
#################################
$2."%
The images are mean centered by subtracting the mean image from each image vector.
m X X
i i
= ! &here

=
=
n
i
i
x
N
m
"
"
############## $2.2%
These vectors are combined! side-by-side! to create a data matrix of size P N $&here P is
the number of images%.
[ ]
N
X X X X . .
2 "
= #################### $2.'%
The data matrix X is multiplied by its transpose to calculate the covariance matrix.
T
X X =
( ) ** ########################## $2.+%
This covariance matrix has up to P eigenvectors associated &ith non-zero eigenvalues!
assuming P<N. The eigenvectors are sorted! high to lo&! according to their associated
eigenvalues. The eigenvector associated &ith the largest eigenvalue is the eigenvector that
finds the greatest variance in the images. The eigenvector associated &ith the second largest
eigenvalue is the eigenvector that finds the second most variance in the images. This trend
continues until the smallest eigenvalue is associated &ith the eigenvector that finds the least
variance in the images.
2.1. Recognizing Images through Eigenspace:
,dentifying images through eigenspace pro-ection ta.es three basic steps. /irst the
eigenspace must be created using training images are pro-ected into the eigenspace.
/inally! the test images are identified by pro-ecting them into the eigenspace and
comparing them to the pro-ected training images.
2.1.1. Create Eigenspace:
The follo&ing steps created an eigenspace.
2.1.1.1. Center Data:
Each of the training images must be centered. ubtracting the mean
image from each of the training images centers the training images as
sho&n in e0uation $2.2%. The mean image is a column vector such that
each entry is the mean of all corresponding pixels of the training
images.
2.1.1.2. Create Data Matrix:
1nce the training images are centered! they are combined into a data
matrix of size NP! &here P is the number of training images and each
column is a single image as sho&n in e0uation $2.'%.
"
Eigenspace Projection
2.1.1.3. Create Covariance Matrix:
The data matrix is multiplied by its transpose to create a covariance
matrix as sho&n in e0uation $2.+%.
2.1.1.. Compute Eigenva!ues " Eigenvectors:
The eigenvalues and corresponding eigenvectors are computed for the
covariance matrix.
AV V = ################### $2.2%
3ere V is the set of eigenvectors associated &ith the eigenvalues 4.
2.1.1.#. $r%er Eigenvectors:
1rder the eigenvectors
V v
i

according to their corresponding
eigenvalues

i

from high to lo&. Keep only the eigenvectors


associated with non-zero eigenvales. This matrix of eigenvectors is
the eigenspace V! &here each column of V is an eigenvector.

=
nm n n
m
m
v v v
v v v
v v v
V
. .
. . . . .
. . . . .
. .
. .
2 "
2 22 2"
" "2 ""
########### $2.5%
2.1.2. Project &raining Images:
Each of the centered training images ( )
i
x is pro-ected into the eigenspace. To
pro-ect an image into the eigenspace! calculated the dot product of the image
&ith each of the ordered eigenvector.
i T i
x V x = ############################ $2.6%
There fore! the dot product of the image and the first eigenvector &ill be the
first value in the ne& vector. The ne& vector of the pro-ected image &ill
contain as many values as eigenvectors.
2.1.3. I%enti'( &est Images:
Each test image is first mean centered by subtracting the mean image! and is
then pro-ected into the same eigenspace defined by V.
m ! !
i i
= ! &here

=
=
n
i
i
x
N
m
"
"
############ $2.7%
4nd
i T i
y V y =
############################# $2.8%
The pro-ected test image is compared to every pro-ected training image and
the training image that is found to be the closest to the test image is used to
identify the training image. The images can be compared using any number of
similarity measures. 3ere &e used the 9eural 9et&or. Tool for this purpose.
The follo&ing is an example of identifying images through eigenspace
pro-ection. :et the four images in /igure 2." be training images and let the
additional image in /igure 2." be a test image.
2
Eigenspace Projection
The four training images and the mean image are:

=
2"6
222
;
2'7
''
22"
+7
228
222
"
x
!

=
2
222
"6
2+6
"7
222
2+
2"8
";
2
x
!

=
225
26
2+'
2++
28
2'2
2'+
'2
"85
'
x
!

=
2'2
222
2+8
222
;
222
22+
22'
222
+
x
!

=
;; . "6;
2; . 2;2
22 . "26
;; . 2+5
2; . 26
22 . 2+7
2; . "'2
2; . "65
2; . "6"
m
The centered images are:

=
;; . +6
2; . +8
22 . "26
;; . 7
2; . 2
62 . 2
2; . 7+
2; . 22
2; . 2'
"
x
!

=
;; . "57
2; . +8
22 . "";
;; . "
2; . 8
62 . 5
2; . ";7
2; . +2
2; . "5"
2
x
!

=
;; . 25
2; . "+7
62 . ""2
;; . 2
2; . '"
22 . "5
2; . ";"
2; . "+"
2; . 2+
'
x
!

=
;; . 52
2; . +8
62 . "2"
;; . 8
2; . 26
62 . 5
2; . 8"
2; . +5
2; . 7'
+
x
=
"
x =
2
x =
'
x =
+
x
=
"
y
)igure 2.1: )our training images *
+ ' 2 "
! ! ! x x x x + " one test image
"
y
Combine all the centered training images into one data matrix:

=
;; . 52 ;; . 25 ;; . "57 ;; . +6
2; . +8 2; . "+7 2; . +8 2; . +8
62 . "2" 62 . ""2 22 . ""; 22 . "26
;; . 8 ;; . 2 ;; . " ;; . 7
2; . 26 2; . '" 2; . 8 2; . 2
62 . 5 22 . "5 62 . 5 62 . 2
2; . 8" 2; . ";" 2; . ";7 2; . 7+
2; . +5 2; . "+" 2; . +2 2; . 22
2; . 7' 2; . 2+ 2; . "5" 2; . 2'
X
Eigenspace Projection
Calculate the covariance matrix:
'










=
'668+ "";77 258'6 6" "7'" "+65 22777 826+ '5++5
"";77 28+;' 228"8 '85 52'6 2 . '2"6 2;;86 27;"6 +72"
258'6 228"8 25258 "662 2 . 5+2 ' . 2"2' +25;+ 22;7+ 2+;;;
6" '85 "662 "2; '5+ 67 ""77 '2+ ""'
"7'" 52'6 2 . 5+2 '5+ "758 2 . 6+5 "2+6 272" ';+
"+65 2 . '2"6 ' . 2"2' 67 2 . 6+5 62 . '52 2 . "885 2 . ';++ 2 . 666
22777 2;;86 +25;+ ""77 "2+6 2 . "885 '6276 "8"22 2'"28
826+ 27;"6 22;7+ '2+ 272" 2 . ';++ "8"22 256+6 '5'8
'5++5 +72" 2+;;; ""' ';+ 2 . 666 2'"28 '5'8 '52"6
T
X X
The ordered non-zero eigenvectors $
' 2 "
! ! v v v
% of the covariance matrix < the
corresponding eigenvalues $
' 2 "
! !
% are:

=
+;22 . ;
285' . ;
25;" . ;
;;77 . ;
;'2; . ;
;'"6 . ;
+685 . ;
2672 . ;
'252 . ;
"
v

=
+'2+ . ;
+8"6 . ;
"""2 . ;
;;'2 . ;
";2" . ;
;+68 . ;
;++' . ;
+772 . ;
222" . ;
2
v

=
'8;7 . ;
+;"" . ;
27+2 . ;
;666 . ;
22"8 . ;
;5'2 . ;
';82 . ;
'+6; . ;
25'5 . ;
'
v
"2'22;
"
= 2;6;;
2
= 2267;
'
=
The eigenspace is defined by the pro-ection matrix:




=
'8;7 . ; +'2+ . ; +;22 . ;
+;"" . ; +8"6 . ; 285' . ;
27+2 . ; """2 . ; 25;" . ;
;666 . ; ;;'2 . ; ;;77 . ;
22"8 . ; ";2" . ; ;'2; . ;
;5'2 . ; ;+68 . ; ;'"6 . ;
';82 . ; ;++' . ; +685 . ;
'+6; . ; +772 . ; 2672 . ;
25'5 . ; 222" . ; '252 . ;
V
Eigenspace Projection
The four centered training images pro-ected into eigenspace are:

= =
2557 . 85
';5; . ""6
;72" . ";'
= " "
x V x
T
!

= =
++6+ . +6
2768 . 87
82'" . 252
= 2 2
x V x
T
+

= =
"+'2 . +5
8;;2 . "22
65'5 . 228
= ' '
x V x
T
!

= =
2527 . 82
772" . ";5
2++6 . "'8
= + +
x V x
T
The test image vie&ed as a vector < the centered test image are:

=
2
222
+
2++
2"
2+5
++
2++
2;
"
y
!

=
"57.;; -
+8.2;
"2'.22 -
2.;; -
5.2; -
2.22 -
77.2; -
56.2;
"2".2; -
"
y
The pro-ected test image is:

= =
2;.5;'6 -
7;.6+65 -
255.5+68 -
= " "
y V y
T
9o&! the pro-ected images are used in the 9eural 9et&or. Tool to identify the
image.
4ppendix: C
2
,ource Co%e *In M-&.-/+
% No. of Images
n=str2num(input('Enter No. of Training Images: ','s'));
% Image Folder at!
pat!=input('Enter Folder "oot at! For Training: ','s');
% Training Image Input
for i=#:n
str=input('Enter Folder Name $ontaining Image: ','s');
apat!=%pat!,'&',str';
str=input('Enter Image File Name %(i)e: img#': ','s');
apat!=%apat!,'&',str';
apat!=%apat!,'.*mp'';

tmp=dou*le(imread(apat!,'*mp'));
%d#,d2'=si+e(tmp);
m=#;
for ,=#:d#
for )=#:d2
-f(m,i)=tmp(,,));
m=m.#;
end
end
end
% Test Image at!
str=input('Enter /imulation Folder: ','s');
apat!=%pat!,'&',str';
% Test Image Input
str=input('Enter /imulation File: ','s');
apat!=%apat!,'&',str,'.*mp'';
% $reating 0ean $entered Image
for i=#:(d#1d2)
temp(i,#)=2;
for ,=#:n
temp(i,#)=temp(i,#).-f(i,,);
end
end
ma=temp3n;
% -f is a (d#1d2) 4 n dimention 0atri-.
,ource Co%e *In M-&.-/+
for ,=#:n
5
-*(:,,)=-f(:,,)5ma;
end
% $reating $o6arian7e 0atri-
r!o=-*1transpose(-*);
%eigen6e7tor,eigen6alue'=eig(r!o);
% /ele7ting Non58ero Eigen 9alues : $orresponding 9e7tors
%d#,d2'=si+e(eigen6alue);
,=#;
for i=#:d#
if (eigen6alue(i,i));2
e6al(,)=eigen6alue(i,i);
e6e7tor(:,,)=eigen6e7tor(:,i);
,=,.#;
end
end
% <rranging Eigen6e7tors a77ording to t!e =es7ending order of t!e Eigen6alues
,=#;
%d>,d?'=si+e(e6al);
for )=#:d?
%6,i'=ma-(e6al);
e6e7(:,,)=e6e7tor(:,i);
e6al(i)=2;
,=,.#;
end
% $reating Eigenspa7e
6t=transpose(e6e7);
-f*=6t1-*;
tm=dou*le(imread(apat!,'*mp'));
%d#,d2'=si+e(tm);
m=#;
for ,=#:d#
for )=#:d2
@(m,#)=tm(,,));
m=m.#;
end
end
@*=@5ma;
@f*=6t1@*;
6

Anda mungkin juga menyukai