Finding Rank of Kernel
Is there a function in OpenCV to find the rank of a matrix or kernel? I need to know this so that I can know whether the kernel or matrix is separable.
Is there a function in OpenCV to find the rank of a matrix or kernel? I need to know this so that I can know whether the kernel or matrix is separable.
The answer can be found e.g. here: http://stackoverflow.com/questions/37...
From there, extracting: 1) first we compute the SVD
Mat s, u, vt;
SVD::compute(M, s, u, vt);
2) Now we have singular values in s
and rotation matrices (you can ignore those) in u
and vt
. Next we could count the number of non-zero singular values, which is equal to the rank:
int rank = countNonZero(s);
However, due to limited numerical precision, some singular values will be nearly-zero and we might (and probably will) want to count them as zeros, working with some threshold:
int rank = countNonZero(s > thr);
In the link above, they recommend value of the threshold thr
as 0.0001
. I think that's a bit too high, but that depends on what your problem is and how different your singular values will be. I wouldn't go below 1e-16
, but maybe something like thr = 1e-10 * s.at<double>(0,0)
isn't a bad choice in my opinion, weighting by the largest singular value...
Asked: 2016-06-13 06:26:44 -0600
Seen: 1,200 times
Last updated: Jun 13 '16
GpuMat submatrix out of GpuMat object?
Sobel derivatives in the 45 and 135 degree direction
multiply two points and matrix
different step size output for cv::Mat::step1
How to operate on each pixel of a cv2.cv.Mat with a 3 x 3 matrix?
missing cv::Mat::zeros(int ndims, const int* sz, int type)
I think that you can use SVD class to decompose and hence find rank
Hi LBerger, could you explain how to use it by an example? I don't understand from the documentation what the values s,u and v are suppose to be? And what exactly does it return and from output, how do we calculate rank?
SVD calculate matrix Singular value decomposition. Number of singular value is equal to rank.
so mat object 's'(variable used by you in first comment) contains the calculated singular values right? I am confused as to how to find the rank i.e the number of singular values from this 's' object?
Yes you can find an example here Mat filter is a separable filter fSepX and fSevY after svd called
I'm sorry but I can't seem to understand what the code is doing? How is it calculating the rank by using fSepX and fSevY?