Ask Your Question
0

Inv function

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

residentelvio gravatar image residentelvio
61 5

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

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

Comments

1

explain "blocked", please.

berak ( 2013-07-03 13:34:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

Jawaher Khemakhem gravatar image Jawaher Khemakhem
197 7

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

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

link delete flag offensive edit

Login/Signup to Answer

Question tools

Follow

subscribe to rss feed

Stats

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

Seen: 59 times

Last updated: Jul 03 '13