title: Eigenvector computation using OpenCV
body: <p>I have this matrix A, representing similarities of pixel intensities of an image. For example: Consider a <code>10 x 10</code> image. Matrix A in this case would be of dimension <code>100 x 100</code>, and element A(i,j) would have a value in the range 0 to 1, representing the similarity of pixel i to j in terms of intensity.</p>
  
  <p>I am using OpenCV for image processing and the development environment is C on Linux. </p>
  
  <p>Objective is to compute the Eigenvectors of matrix A and I have used the following approach:</p>
  
  <pre><code>static CvMat mat, *eigenVec, *eigenVal;
  static double A[100][100]={}, Ain1D[10000]={};
  int cnt=0;
  
  //Converting matrix A into a one dimensional array
  //Reason: That is how cvMat requires it
  for(i = 0;i &lt; affnDim;i++){
    for(j = 0;j &lt; affnDim;j++){
   Ain1D[cnt++] = A[i][j];
    }
  }
  
  mat = cvMat(100, 100, CV_32FC1, Ain1D); 
  
  cvEigenVV(&amp;mat, eigenVec, eigenVal, 1e-300);
  
  for(i=0;i &lt; 100;i++){
    val1 = cvmGet(eigenVal,i,0); //Fetching Eigen Value
  
    for(j=0;j &lt; 100;j++){   
   matX[i][j] = cvmGet(eigenVec,i,j); //Fetching each component of Eigenvector i    
    }
  }
  </code></pre>
  
  <p><strong>Problem:</strong> After execution I get nearly all components of all the Eigenvectors to be zero. I tried different images and also tried populating A with random values between 0 and 1, but the same result.</p>
  
  <p>Few of the top eigenvalues returned look like the following:</p>
  
  <pre><code>9805401476911479666115491135488.000000  
  -9805401476911479666115491135488.000000  
  -89222871725331592641813413888.000000  
  89222862280598626902522986496.000000  
  5255391142666987110400.000000
  </code></pre>
  
  <p>I am now thinking on the lines of using <a href="http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docs/ref/OpenCVRef_BasicFuncs.htm#decl_cvSVD" rel="noreferrer">cvSVD()</a> which performs singular value decomposition of real floating-point matrix and might yield me the eigenvectors. But before that I thought of asking it here. Is there anything absurd in my current approach? Am I using the right API i.e. <a href="http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docs/ref/OpenCVRef_BasicFuncs.htm#decl_cvEigenVV" rel="noreferrer">cvEigenVV()</a> for the right input matrix (my matrix A is a floating point matrix)?</p>
  
  <p>cheers</p>