Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Inv function

I have to obbtain this: (from MAtlab)

 Y = inv(X) returns the inverse of the square matrix X. A warning message is printed if X is badly scaled or nearly singular.

I did in OpenCV with :

 Z=Z.inv(DECOMP_LU);

But here the function I m writing is blocked. DO you know why . Thanks

Inv function

I have to obbtain this: (from MAtlab)

 Y = inv(X) returns the inverse of the square matrix X. A warning message is printed if X is badly scaled or nearly singular.

I did in OpenCV with :

 Z=Z.inv(DECOMP_LU);

But here the function I m writing is blocked. DO you know why . Thanks

THE TESTING OF FUNCTION:

#include <stdio.h>
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>

using namespace cv;

Mat whitening_sqr_meanDistance(Mat X);


int main(){
Mat X=imread("/home/elvio/workspace/aws/src/andaina.JPG");
Mat mu;
namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
imshow("Image Display", X);
waitKey(0);
destroyWindow("Image Display");

X=X.reshape(X.channels(),X.rows*X.cols);
mu=whitening_sqr_meanDistance(X);

namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
imshow("Image Display", mu);
waitKey(0);
destroyWindow("Image Display");

}


  Mat whitening_sqr_meanDistance(Mat X){

  Mat X_f,X_tr,A,V,D,S,Z,Xwh,whMat;
  Scalar mu,mu_wh;
  SVD svd;
  double epsilon = 0.0001;
  int r,c,sz1;

  X.convertTo(X_f,CV_32FC3);
  X_f=X_f.reshape(1,X.rows*X.cols);

  mu = mean(X_f);
  subtract(X_f,mu,X_f);
  transpose(X_f,X_tr);
  A=X_tr * X_f;

  V = svd(A).u;
  D = svd(A).w;

  sz1=X.rows;
  r= D.rows;
  c= D.cols;

  S= Mat::eye((int)r*epsilon,(int)c*epsilon,CV_32FC3);
  printf("Hello\n");
  S=S*epsilon;


  Z=(D+S);

  Z=Z.inv(DECOMP_LU);
  printf("Hello\n");
  sqrt(Z,S);
  whMat=V*S;

  printf("Hello\n");
  Xwh=X*whMat;

  mu_wh=mean(Xwh);
  subtract(Xwh,mu_wh,Xwh);

  Z= Mat::zeros(r,c,CV_32FC3);

  sqrt(Xwh,Z);

 return Z;
 }