Setting a Gaussian curve to a specific peak of a histogram in C ++

I have two questions regarding setting a gauss curve to the top of the histogram. My first question is very simple:

  • How can I fit a gauss curve for the entire histogram? Does this only mean that I need to find out and calculate the average value (μ) and the deviation (ϭ) of the histogram and enter them in the formula for the Gaussian curve?

Will the following be true: Suppose (as an example) I have a histogram of an image with 5 color values. On the X-Axes there are these 5 color values, and on the Y-axes there are frequencies of each of these values. i.e:.

value 1: 1 time

value 2: 4 times

value 3: 7 times

value 4: 3 times

value 5: 2 times

Now the average value (μ) will be equal to 3 (μ = 3).

And the deviation (ϭ) will be 0.9 (ϭ = 0.9). formulaic:

Now, do I use these values ​​in the density function form to calculate a Gaussian curve?

It is right? Unfortunately, I'm a little unsure of the mathematical background.

  1. My second question is a little more complicated: This time I have a histogram with several peaks, but I only want to fit the Gaussian curve to the highest peak. So, I look through all the histogram bins with a simple loop and find one intensity value on the x axis (which contains the image intensities) with most frequencies (shown on the y axis). It will be the highest peak. But how do I know about a deviation? Moreover, I don’t know which of the intensity values ​​I should include in my calculations. As far as I know, the turning point of the Gaussian curve lies in μ + ϭ and μ-ϭ. Can this help solve the problem.

I'm sorry this question is a little mathematical, but I have not found a better place to ask it. I also read some of these topics, but unfortunately they finally did not answer my question.

Thanks for your help!

Regards Mark

+4
source share
2 answers

Your approach to estimating the parameters of one Gaussian is correct, I think.

For a few Gaussians, you may need to look at a mixture of models or, more specifically, a mixture of Gausses. Just a few notes:

  • (you probably already knew that) the strongest Gaussian in the mix should not be the one with the highest peak
  • If you have the sum of two gausses with different average values, the peaks in the histogram will not correspond to the average values
  • Using the height of one peak in a discrete histogram is probably not a good idea: the actual peak may be between two histograms. [Clarification: in this case, the counter in both boxes can be significantly lower than for the peak centered in the hopper.] In addition, for most types of data, your histogram will contain a lot of noise. At least use some sort of histogram averaging filter.
+3
source

Your simple single peak approach should be fine. [BTW I think this is the right programming question if it relates to images.]

A few peaks are more difficult. The peak resolution process is called deconvolution ( http://en.wikipedia.org/wiki/Deconvolution ), and usually there is no single answer. You may need to decide how many peaks there are or what is the minimum dispersion of the peak (otherwise you could create a peak for each bin :-)).

+4
source

All Articles