1

I have some discrete values and assumption, that these values lie on a Gaussian curve. There should be an algorithm for max-calculation using only 3 discrete values. Do you know any library or code in C/C++ implementing this calculation?

Thank you!

P.S.: The original task is auto-focus implementation. I move a (microscope) camera and capture the pictures in different positions. The position having most different colors should have best focus.

EDIT This was long time ago :-( I'just wanted to remove this question, but left it respecting the good answer.

Valentin H
  • 7,240
  • 12
  • 61
  • 111
  • 3
    Basically, you want a *Gaussian fit*. This can be done by brutally [fitting a parabola on the logarithm of your y](https://ccrma.stanford.edu/~jos/sasp/Fitting_Gaussian_Data.html); in your particular case this is very easy, since with three points you identify a single a parabola that passes through them. – Matteo Italia Aug 14 '11 at 22:10
  • Thanks. The link is unfortunatelly a Matlab implementation, but "Gaussian fit" is a goot starting point to google. – Valentin H Aug 14 '11 at 22:38
  • I wrote an extensive answer about your specific case, check it out. :) – Matteo Italia Aug 14 '11 at 23:27
  • What kind of microscope is this for? When you say "most different colors" are you talking about the width of a histogram? Or are you really looking at RGB camera images? – Jonas Heidelberg Sep 16 '11 at 15:46
  • @Jonas Heidelberg: The microscope is composed (self made) out of different parts - none off the shelf. Currently I do really look at each pixel (only Green actually) of each 100th line of a picture. Meanwhle, we found out, that this method is not stable enough, e.g. because some (bad focus) pictures create gradients - which result s in many colors. However, The Gaussian fit will be helpfull with any other heuristics. Thank you! – Valentin H Sep 19 '11 at 22:43
  • The question is embarrassing:-( Unfortunatelly, the gaussian fit didn't help our system. Math and real world couldn't agree at this point - e.g. moving microscope up and down the same number of steps didn't result in same position. What really helped was the fuzzy logic making use of many-many domain-knowledge tricks. I still wonder how it works, but no competitor could do it till now :-) [Helios](http://www.medicalexpo.com/prod/aeskudiagnostics/automatic-immunofluorescence-assay-analyzers-67515-524995.html) – Valentin H Mar 19 '15 at 07:48

1 Answers1

10

You have three points that are supposed to be on a Gaussian curve; this means that they lie on the function:

generic Gaussian function

If you take the logarithm of this function, you get:

log of the Gaussian function

which is just a simple 2nd grade polynomial, i.e. a parabola with a vertical axis of simmetry:

generic 2nd grade polynomial

with

coefficient definitions

So, if you know the three coefficients of the parabola, you can derive the parameters of the Gaussian curve; incidentally, the only parameter of the Gaussian function that is of some interest to you is b, since it tells you where the center of the distribution, i.e. where is its maximum. It's immediate to find out that

b from beta and alpha

All that remains to do is to fit the parabola (with the "original" x and the logarithm of your values). Now, if you had more points, a polynomial fit would be involved, but, since you have just three points, the situation is really simple: there's one and only one parabola that goes through three points.

You now just have to write the equation of the parabola for each of your points and solve the system:

system of the three points

(with y and z, where the zs are the actual values read at the corresponding x)

This can be solved by hand (with some time), with some CAS or... looking on StackOverflow :) ; the solution thus is:

solution of the parabola through three points

So using these last equations (remember: the ys are the logarithm of your "real" values) and the other relations you can easily write a simple algebraic formula to get the parameter b of your Gaussian curve, i.e. its maximum.

final result

(I may have done some mess in the calculations, double-check them before using the results, anyhow the procedure should be correct)

(thanks at http://www.codecogs.com/latex/eqneditor.php for the LaTeX equations)

Community
  • 1
  • 1
Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • That system of equations is linear in alpha, beta, and gamma, so solving is VERY easy. – Ben Voigt Aug 15 '11 at 00:22
  • @Ben: feel free to add all the Gauss-Jordan steps, as much as I'm concerned I wrote enough LaTeX this night :P (I love LaTeX, but here on SO it's quite cumbersome). – Matteo Italia Aug 15 '11 at 00:43
  • Than you! Great explanation and usefull links! However, I still don't believe, that there is no available C-library doing this. I'm afraid, I will implement it myself:-( – Valentin H Sep 16 '11 at 13:10