# Revision history [back]

I modified the code as in the below link

http://pastebin.com/pZGEYNwb

And for this I am getting distance vector as below

http://pastebin.com/9KCr7LTs

The above values are the distances calculated between a particular test image and 400 training images, where the test image is one among the training image itself.

So as per your comment, have I went wrong somewhere when I modified.

I modified the code as in the below link

http://pastebin.com/pZGEYNwb

And for this I am getting distance vector as below

http://pastebin.com/9KCr7LTs

The above values are the distances calculated between a particular test image and 400 training images, where the test image is one among the training image itself.

So as per your comment, have I went wrong somewhere when I modified.modified. Can you please tell me whether the distance vector I got is proper or not.

 3 No.3 Revision berak 31856 ●4 ●76 ●300

I modified the code as in the below link

http://pastebin.com/pZGEYNwb

Mat covar, invcovar, mean;
calcCovarMatrix(_projections, covar, mean, CV_COVAR_NORMAL|CV_COVAR_ROWS,CV_64F);   //Calculating the covariance matrix

invert(covar, invcovar, DECOMP_SVD); //Calculating the inverse covariance matrix
//////For Calculating Mahalanobis distance///////////////

for(size_t sampleIdx = 0; sampleIdx <_projections.size(); sampleIdx++) {

double dist=Mahalanobis( _projections[sampleIdx], q, invcovar );
// Add to the resulting distance array:
if(distances.needed()) {

distances.getMat().at<double>(sampleIdx) = dist;

}
if((dist < minDist) && (dist < _threshold)) {
minDist = dist;
minClass = _labels.at<int>((int)sampleIdx);
}
}


And for this I am getting distance vector as below

http://pastebin.com/9KCr7LTs

The above values are the distances calculated between a particular test image and 400 training images, where the test image is one among the training image itself.

So as per your comment, have I went wrong somewhere when I modified. Can you please tell me whether the distance vector I got is proper or not.

I modified the code as in the below link

http://pastebin.com/pZGEYNwb

Mat covar, invcovar, mean;
calcCovarMatrix(_projections, covar, mean, CV_COVAR_NORMAL|CV_COVAR_ROWS,CV_64F);   //Calculating the covariance matrix

invert(covar, invcovar, DECOMP_SVD); //Calculating the inverse covariance matrix
//////For Calculating Mahalanobis distance///////////////
distance///////////////"_projections"->Training images(40x10)//////"q" -> TestSample///////

for(size_t sampleIdx = 0; sampleIdx <_projections.size(); sampleIdx++) {

double dist=Mahalanobis( _projections[sampleIdx], q, invcovar );
// Add to the resulting distance array:
if(distances.needed()) {

distances.getMat().at<double>(sampleIdx) = dist;

}
if((dist < minDist) && (dist < _threshold)) {
minDist = dist;
minClass = _labels.at<int>((int)sampleIdx);
}
}


And for this I am getting distance vector as below

http://pastebin.com/9KCr7LTs

The above values are the distances calculated between a particular test image and 400 training images, where the test image is one among the training image itself.

So as per your comment, have I went wrong somewhere when I modified. Can you please tell me whether the distance vector I got is proper or not.