Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

click to hide/show revision 3
No.3 Revision

updated 2015-09-15 06:17:17 -0600

berak gravatar image

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.