Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVD computing different result in Matlab and OpenCV

I wonder why there is sign difference in result for SVD computing in Matlab and OpenCV. I input the same matrix

          3.65E+06  -2.09E+06   0
 YY =    -2.09E+06  2.45E+06    0
           0         0          0

[U,S,V] = svd(YY);//Matlab


        -0.798728902689475  0.601691066917623   0
   V =  0.601691066917623   0.798728902689475   0
         0                  0                   1

cv::SVD::compute(YY, S, U, V);//opencv

     0.798839   -0.601544   0
V =  0.601544   0.798839    0
     0          0           1

I know that they use the same algo, why there is sign difference? Thanks

like image 569
Bryanyan Avatar asked Apr 17 '13 06:04

Bryanyan


People also ask

What does SVD return in Matlab?

Description. S = svd( A ) returns the singular values of matrix A in descending order. [ U , S , V ] = svd( A ) performs a singular value decomposition of matrix A , such that A = U*S*V' .

How to use svd function in MATLAB?

svd (MATLAB Functions) The svd command computes the matrix singular value decomposition. s = svd(X) returns a vector of singular values. [U,S,V] = svd(X) produces a diagonal matrix S of the same dimension as X , with nonnegative diagonal elements in decreasing order, and unitary matrices U and V so that X = U*S*V'.


1 Answers

Which version of OpenCV are you using?

From http://code.opencv.org/issues/1498 it seems recent versions of OpenCV no longer use LAPACK to do SVD (as used by Matlab, I think). So the assumption that the same algorithm is being used might not be correct.

Of course YY=USV'

If you negate the first columns of U and V:

U(:,1)=-U(:,1);
V(:,1)=-V(:,1)

You will find USV' still equals YY. This works for your particular case because YY is symmetric (YY=YY').

like image 124
Bull Avatar answered Sep 28 '22 10:09

Bull