0

I am using SVD function to get values. In my Opencv, I wrote

Mat w, u, vt;
SVD::compute(A, w, u, vt);

After compare the values against the MATLAB, it seems u and vt matrix does not match with what the MATLAB returns. The values actually match, but sometime, U(:1), and VT(:1) is negated from what OpenCV returns. Sometime, VT elements are negated and flipped. Although U*VT returns same value as MATLAB, U and VT itself is different than MATLAB (randomly) and I am not sure what is causing this. I am using OpenCV 2.4 and can you help me on how to solve this?

Thanks.

user2168
  • 309
  • 8
  • 15

2 Answers2

1

It may be because the singular values are ordered differently, i.e. in A = u w vt, the diagonal matrix w (of singular values) has the entries ordered differently from MATLAB. In MATLAB the singular values are ordered in decreasing order on the main diagonal.

vsoftco
  • 55,410
  • 12
  • 139
  • 252
1

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.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64