How to get most often appearing number in a cv::Mat
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
also depends on the type of your Mat, no ? and what do you need it for ? do you have multiple channels ? or float data ?
only single channel, it is 32FC1.
I need the most often appearing range to get a reliable depth. You could assume the image is already a roi.
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.
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.
But I have a question for NaN, what will calcHist do for NaN?
you mean NaN's in your original depth image, not in the histogram, right ?
try to patchNaNs() before making the histogram