Ask Your Question
3

Find Peaks in Histogram

asked 2016-07-14 03:37:50 -0500

JakeM gravatar image

Is there an existing OpenCV function that can tell me the peaks of a histogram? For example; in the following 1d histogram/image (gray-scale) I'd like to get the bin numbers (or ranges) for the 2 or 3 general peaks. PS: what is the technical term for a 'peak' in a histogram?

image description

Maybe there is a function that can sort the bins from highest to lowest (number of pixels for that bin)? I know I can get use cv::minMaxLoc() to find out the highest and lowest bin numbers. Is there anything that can sort the bins?

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
3

answered 2016-07-14 09:21:36 -0500

pklab gravatar image

Please use search function on this site or use tag peaks on this site to locate examples like this or this.

edit flag offensive delete link more
0

answered 2019-06-27 13:50:00 -0500

The general term for a histogram peak in statistics is "mode," (see for example https://link.springer.com/chapter/10....) so for example if you have two local peaks, that would be called a "bimodal" distribution. In image histograms, it's common to have several strong modes. The main challenge in this type of case is the noise, so you would probably want to smooth the histogram before doing some kind of local maximum detection. I would look at what information you're trying to extract and decide how many modes you "should" have, and apply a blur. Like Avio says, the world is full of find_peak functions from that point. The art here is going to be in figuring out how much blur to use, which will be determined by how much separation you expect between the modes.

edit flag offensive delete link more
0

answered 2016-07-14 06:11:59 -0500

MRDaniel gravatar image

You want local maxima.

The histogram is a mat, so you can get the value of each index.

How you choose to do this is up to you. But a sliding window, where you have the previous value, current value and next value. If prev < current > next then you have a peak.

That's a pretty crude approach so perhaps you may want to smooth or normalize you values first.

edit flag offensive delete link more

Comments

«If prev < current > next then you have a peak.» it's an invitation to reinvent the wheel and a bad idea in general. The world is full of find_peaks() functions, it's just a matter of finding them and find the most suitable to each problem. Here is a good place to start.

Avio gravatar imageAvio ( 2018-06-15 04:35:37 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-07-14 03:37:04 -0500

Seen: 5,686 times

Last updated: Jun 27