SVD computing different result in Matlab and OpenCV
Asked Answered
F

3

15

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

Fredericksburg answered 17/4, 2013 at 6:49 Comment(0)
F
12

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').

Fragile answered 19/4, 2013 at 7:28 Comment(0)
P
3

The results of the SVD need not be unique. For example, I = UIV' for any unitary V = U. The example you give above in particular is rank deficient, so there is no reason to expect uniqueness.

Procreant answered 23/7, 2014 at 20:16 Comment(0)
N
2

Singular Value Decomposition is only defined up to a sign; the signs of U and V are arbitrary, and if they are different between MATLAB and OpenCV that does not indicate a problem.

Nagano answered 18/5, 2014 at 10:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.