Ask Your Question
0

How to get most often appearing number in a cv::Mat

asked 2017-06-16 17:15:52 -0600

waschbaer gravatar image

updated 2017-06-17 08:17:45 -0600

HI,

I want to get the statistics of a cv::Mat, to get the most often appearing range of numbers(so not a single number, but a range). I think I can use histogram, but I am not sure wether there is a more easier way to do this, because to calculate histogram, we need to set number of bins and range before calculate, this is however not robust for me.

Best, waschbaer

edit retag flag offensive close merge delete

Comments

also depends on the type of your Mat, no ? and what do you need it for ? do you have multiple channels ? or float data ?

berak gravatar imageberak ( 2017-06-16 19:02:20 -0600 )edit

only single channel, it is 32FC1.

waschbaer gravatar imagewaschbaer ( 2017-06-17 08:16:34 -0600 )edit
1

I need the most often appearing range to get a reliable depth. You could assume the image is already a roi.

waschbaer gravatar imagewaschbaer ( 2017-06-17 08:18:25 -0600 )edit

for float data, you can't avoid "binning" it, right ? (unless you convert it to "fixed point" by multiplying with some large int, and then convert to int)

you could use minMaxLoc() to get the ranges for calcHist()

then, split the histogram in 2 halves, apply minMaxLoc again on both, and use the maxvalue from the lower & upper half for your depth range.

berak gravatar imageberak ( 2017-06-17 08:30:27 -0600 )edit

Yes, you are right.. I am now using minmaxloc to get a flexible range for every roi, but for number of bins I think I will try to ensure for each bin the size is no larger then 5 or 10 centmeter. Then it should be robust enough.

waschbaer gravatar imagewaschbaer ( 2017-06-17 08:42:28 -0600 )edit

But I have a question for NaN, what will calcHist do for NaN?

waschbaer gravatar imagewaschbaer ( 2017-06-17 08:54:18 -0600 )edit

you mean NaN's in your original depth image, not in the histogram, right ?

try to patchNaNs() before making the histogram

berak gravatar imageberak ( 2017-06-17 09:43:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-17 12:53:27 -0600

waschbaer gravatar image

I find out it will ignore all NaN and do not assign to a bin. That is nice actually. Thank you for the comments.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-16 17:15:52 -0600

Seen: 322 times

Last updated: Jun 17 '17