Ask Your Question
0

Parameters of cv::SVDecomp

asked 2018-09-25 07:36:08 -0600

Grillteller gravatar image

updated 2018-09-26 05:32:05 -0600

Hi,

what are the parameters w, u, vt of cv::SVDecomp(src, w, u, vt) in comparison to Matlab's

[U,S,V] = svd(src);

I need the submatrices for further calculations that I already have given in Matlab. Can I directly translate w to U, u to S and vt to V. It seems like they are having varying Matrix sizes. I did not find further explanations on the SVDecomp function (e.g. here: documentation)

Edit:
I tried more stuff. I have the src matrix of size 27x18 (edited): In Matlab I get as result for the sizes U(27x27), S(27x18), V(18x18) which solves the SVD equation src=USV'

In OpenCV I open the same matrix src(27x18) and I get as result with cv::SVD::FULL_UV:
w(1x18), u(18x18), vt(27x27) which does not solve the equation. I am quite confused right now, what is going on in openCV SVD.

edit retag flag offensive close merge delete

Comments

hmm, i cannot reproduce your numbers (opencv version ?)

Mat_<float> src(27,27), W,U,VT;
SVDecomp(src,W,U,VT,SVD::FULL_UV);
cout << W.size() << U.size() << VT.size() << endl;

[1 x 27][27 x 27][27 x 27]

(and W is only the trace, the diagonal of a 27x27 Matrix)

berak gravatar imageberak ( 2018-09-26 04:42:21 -0600 )edit

hey, even for the edited version i get [1 x 18][27 x 27][18 x 18] (imho, you messed up U and VT, please don't be that sloppy !)

berak gravatar imageberak ( 2018-09-26 05:33:04 -0600 )edit
1

Sry, had an error in the description. My source matrix is 27x18. Ok, you are even faster than me :D. Wait, I will try in a minimal example and report. I cannot see an error in my std::cout right now -.-

Grillteller gravatar imageGrillteller ( 2018-09-26 05:35:33 -0600 )edit

formula in the answer below will work, if you use:

SVDecomp(src.t(),W,U,VT,SVD::FULL_UV);
berak gravatar imageberak ( 2018-09-26 05:40:13 -0600 )edit

Ok, I am dumb. I assumed my matrix is 27 x 18 because I got it from src.size(). In fact the matrix is 18 x 27 which I could get from src.size().height and src.size().width. So no error in the SVD, but I got confused really hard with the size function. cv::Mat E_new(27, 18, CV_64F); std::cout << E_new.size() << " " << E_new.size().height << " and " << E_new.size().width << std::endl;

Grillteller gravatar imageGrillteller ( 2018-09-26 06:00:10 -0600 )edit
1

the WxH, rowsXcols thing ... it is confusing..

berak gravatar imageberak ( 2018-09-26 06:03:21 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-09-26 04:47:38 -0600

berak gravatar image

no idea if it solves your problem, but to reconstruct src, it would be like:

Mat_<float> src(5,5), W,U,VT;
src  << 1,2,3,4,5,
        1,2,3,4,5,
        1,2,3,4,5,
        1,2,3,4,5,
        1,2,3,4,5;

SVDecomp(src, W, U, VT, SVD::FULL_UV);

Mat_<float> WD(5,5);
W.copyTo(WD.diag());

Mat rec = VT.t() * WD * U.t();
cout << rec << endl;

[1.0000001, 1.0000001, 1.0000001, 1.0000001, 1.0000001;
 2.0000002, 2.0000002, 2.0000002, 2.0000002, 2.0000002;
 3, 3, 3, 3, 3;
 4.0000005, 4.0000005, 4.0000005, 4.0000005, 4.0000005;
 5.0000005, 5.0000005, 5.0000005, 5.0000005, 5.0000005]

(it returns the transposed src / result)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-09-25 07:36:08 -0600

Seen: 2,415 times

Last updated: Sep 26 '18