SHARE
TWEET

Modified Mahalanobis Distance

a guest Sep 14th, 2015 247 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Mat covar, invcovar, mean;
  2. calcCovarMatrix(_projections, covar, mean, CV_COVAR_NORMAL|CV_COVAR_ROWS,CV_64F);   //Calculating the covariance matrix
  3.      
  4. invert(covar, invcovar, DECOMP_SVD); //Calculating the inverse covariance matrix
  5.  //////For Calculating Mahalanobis distance///////////////
  6.    
  7. for(size_t sampleIdx = 0; sampleIdx <_projections.size(); sampleIdx++) {
  8.                            
  9.  double dist=Mahalanobis( _projections[sampleIdx], q, invcovar );
  10.          // Add to the resulting distance array:
  11.         if(distances.needed()) {
  12.                
  13.             distances.getMat().at<double>(sampleIdx) = dist;
  14.  
  15.         }
  16.         if((dist < minDist) && (dist < _threshold)) {
  17.             minDist = dist;
  18.             minClass = _labels.at<int>((int)sampleIdx);
  19.         }
  20.      }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top