Ask Your Question
0

Finding Rank of Kernel

asked 2016-06-13 06:26:44 -0600

kevgeo gravatar image

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.

edit retag flag offensive close merge delete

Comments

I think that you can use SVD class to decompose and hence find rank

SVD::compute(kernel,s,u,v);
LBerger gravatar imageLBerger ( 2016-06-13 08:35:20 -0600 )edit

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?

kevgeo gravatar imagekevgeo ( 2016-06-13 22:38:04 -0600 )edit

SVD calculate matrix Singular value decomposition. Number of singular value is equal to rank.

LBerger gravatar imageLBerger ( 2016-06-14 02:05:36 -0600 )edit

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?

kevgeo gravatar imagekevgeo ( 2016-06-14 04:45:28 -0600 )edit

Yes you can find an example here Mat filter is a separable filter fSepX and fSevY after svd called

LBerger gravatar imageLBerger ( 2016-06-14 06:20:47 -0600 )edit

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?

kevgeo gravatar imagekevgeo ( 2016-06-15 12:46:55 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-16 04:42:17 -0600

BIOS the Zerg gravatar image

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-06-13 06:26:44 -0600

Seen: 1,236 times

Last updated: Jun 13 '16