J
jimgardener
hi
i was trying to learn face recognition using eigenfaces .i came across
a face recog engine written by konrad at www.darnok.com. I came
across the part about euclidean distance calculation in this..can
someone explain the mechanism/maths in it
here are some code snippets in java (from
apollo.nemesis.EigenFaceComputation.java)
the program creates a matrix of weights from training images and then
creates a 1 dim array containing weights calculated from an image to
be checked.
/* wk=weights from taining images , nrfaces=total images in training
set
MAGIC_NR=number of facespaces used for recognition
faceSpace is a double[][] containig calculated facespace
*/
double[][] wk = new double[nrfaces][MAGIC_NR];
for (image = 0; image < nrfaces; image++) {
for (j = 0; j < MAGIC_NR; j++) {
temp = 0.0;
for ( pix=0; pix< length; pix++)
temp += faceSpace[j][pix] * faces[image][pix];
wk[image][j] = Math.abs( temp );
}
}
then input weights is calculated from image to be checked
inputFace is a double[] to represent image to be checked
double[] input_wk = new double[MAGIC_NR];
for (j = 0; j < MAGIC_NR; j++) {
temp = 0.0;
for ( pix=0; pix <length; pix++)
temp += faceSpace[j][pix] * inputFace[pix];
input_wk[j] = Math.abs( temp );
}
I understood the maths till now..
here is the euclidean distance calculation..this is the part i wish to
know in detail..is this the correct way from a maths viewpoint? Can
someone explain the maths pls?
int idx = 0;
double[] distance = new double[MAGIC_NR];
double[] minDistance = new double[MAGIC_NR];
for (image = 0; image < nrfaces; image++) {
for (j = 0; j < MAGIC_NR; j++)
distance[j] = Math.abs(input_wk[j] - wk[image][j]);
if (image == 0)
System.arraycopy(distance,0,minDistance,0,MAGIC_NR);
if (sum(minDistance) > sum(distance)) {
idx = image;
System.arraycopy(distance,0,minDistance,0,MAGIC_NR);
}
}
divide(minDistance, max(minDistance)+1);
double minD = sum(minDistance);
System.out.println("image is idx "+idx+" distance from face: "+minD);
thanx
jim
i was trying to learn face recognition using eigenfaces .i came across
a face recog engine written by konrad at www.darnok.com. I came
across the part about euclidean distance calculation in this..can
someone explain the mechanism/maths in it
here are some code snippets in java (from
apollo.nemesis.EigenFaceComputation.java)
the program creates a matrix of weights from training images and then
creates a 1 dim array containing weights calculated from an image to
be checked.
/* wk=weights from taining images , nrfaces=total images in training
set
MAGIC_NR=number of facespaces used for recognition
faceSpace is a double[][] containig calculated facespace
*/
double[][] wk = new double[nrfaces][MAGIC_NR];
for (image = 0; image < nrfaces; image++) {
for (j = 0; j < MAGIC_NR; j++) {
temp = 0.0;
for ( pix=0; pix< length; pix++)
temp += faceSpace[j][pix] * faces[image][pix];
wk[image][j] = Math.abs( temp );
}
}
then input weights is calculated from image to be checked
inputFace is a double[] to represent image to be checked
double[] input_wk = new double[MAGIC_NR];
for (j = 0; j < MAGIC_NR; j++) {
temp = 0.0;
for ( pix=0; pix <length; pix++)
temp += faceSpace[j][pix] * inputFace[pix];
input_wk[j] = Math.abs( temp );
}
I understood the maths till now..
here is the euclidean distance calculation..this is the part i wish to
know in detail..is this the correct way from a maths viewpoint? Can
someone explain the maths pls?
int idx = 0;
double[] distance = new double[MAGIC_NR];
double[] minDistance = new double[MAGIC_NR];
for (image = 0; image < nrfaces; image++) {
for (j = 0; j < MAGIC_NR; j++)
distance[j] = Math.abs(input_wk[j] - wk[image][j]);
if (image == 0)
System.arraycopy(distance,0,minDistance,0,MAGIC_NR);
if (sum(minDistance) > sum(distance)) {
idx = image;
System.arraycopy(distance,0,minDistance,0,MAGIC_NR);
}
}
divide(minDistance, max(minDistance)+1);
double minD = sum(minDistance);
System.out.println("image is idx "+idx+" distance from face: "+minD);
thanx
jim