Singular Value Decomposition (SVD) with opencv
Hi, I am using SVD for my algorithm and the decomposition is done by this instruction:
const int N= 16;
Mat x= (Mat_<double>(N, N)<< 23, 24, 24, 23, 22.5, 21.5, 20, 20, 19, 20, 22, 23, 23, 23.5, 24, 25.5,
23.5, 24, 23, 21, 21, 22, 21, 20, 18.5, 18, 19, 20, 20.5, 23, 24, 24,
24, 24, 22, 21, 21.5, 21.5, 21, 20, 19.5, 20, 21, 21, 22, 23, 24, 24,
24.5, 24, 23, 23, 23, 21, 20, 20, 20, 22, 22, 22, 23, 23, 24, 24,
24, 24, 24, 24, 24, 22, 20, 20, 20, 21, 21, 21, 21, 22, 24, 24,
24, 24.5, 25, 24.5, 24, 22, 20, 21, 21, 21, 22, 22, 22, 23, 24, 24,
24, 24.5, 25, 24.5, 24, 22, 20, 22, 23, 23, 24, 24, 23, 22, 22.5, 23,
24.5, 24.5, 24, 24, 23, 22, 22, 23, 24.5, 24.5, 23, 21.5, 21, 21, 22.5, 22.5,
23.5, 24.5, 25.5, 25, 23.5, 24.5, 26, 25.5, 24, 25, 22.5, 20.5, 20.5, 21, 21, 20.5,
24.5, 25.5, 26, 25.5, 24.5, 25, 25.5, 25, 24, 24, 22, 20.5, 20.5, 19.5, 18.5, 19.5,
25.5, 25.5, 26, 26, 25, 25, 25, 25, 23.5, 24, 22, 20, 20, 19.5, 18.5, 21,
24, 24, 24, 24, 24, 24.5, 23, 22.5, 24, 24.5, 23, 20.5, 20, 20, 20.5, 22.5,
24, 24, 24, 24, 24, 24, 23, 22.5, 24, 23.5, 23, 21.5, 20, 19.5, 22, 24,
22.5, 23, 22.5, 22, 23, 23, 22, 21.5, 23, 22, 22, 22, 20, 20.5, 23, 24,
22.5, 21.5, 21.5, 22, 23, 24, 22.5, 20, 21, 20.5, 20.5, 22, 22, 23, 23.5, 23.5,
22.5, 21, 21, 21, 21, 23, 21.5, 20, 20, 20.5, 20.5, 22, 24, 24, 23.5, 23.5);
Mat Sigma= Mat::zeros(N, N, CV_64FC1);
Mat S, U, VT, x_hat, err;
int minLoc[2], maxLoc[2];
double minVal, maxVal;
SVDecomp(x, S, U, VT, cv::SVD::FULL_UV);
/*Please note that S is a column vector and S should be a square diagonal matrix, Assigning the components of the S to the diagonal components of Sigma*/
x_hat= U * Sigma* VT;
cout<< "U * Sigma* VT= "<< endl<< x_hat<< endl;
absdiff(x, x_hat, err);
And the error is really huge!!! (Terminal output)
Reconstruction err: MIN= 0.00135955, MAX= 2.99473, sum= [176.076, 0, 0, 0]
Which is shit! The whole process is done very straight forward with matlab. What's wrong with opencv SVD? Why does the operation loon irreversible?!!!! Your advices are highly appreciated.
minMaxIdx(err, &minVal, &maxVal, minLoc, maxLoc);
cout<< "Reconstruction err: MIN= "<< minVal<< ", MAX= "<< maxVal<< ", sum= "<< ...