Ask Your Question
0

Inv function

asked 2013-07-03 13:24:33 -0600

residentelvio gravatar image

updated 2013-07-03 16:45:44 -0600

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;
 }
edit retag flag offensive close merge delete

Comments

1

explain "blocked", please.

berak gravatar imageberak ( 2013-07-03 13:34:00 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-07-03 13:36:56 -0600

Jawaher Khemakhem gravatar image

updated 2013-07-03 13:39:49 -0600

See here the documentation please post your code so we can help you .I didn't get the problem .

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-03 13:24:33 -0600

Seen: 1,381 times

Last updated: Jul 03 '13