我有一些离散值和假设,这些值位于高斯曲线上。
应该有一个仅使用 3 个离散值进行最大值计算的算法。
您知道 C/C++ 中实现此计算的任何库或代码吗?
谢谢你!
附:
最初的任务是自动对焦的实现。我移动(显微镜)相机并在不同位置拍摄照片。具有最多不同颜色的位置应该具有最佳焦点。
编辑
这是很久以前的事了:-(
我只是想删除这个问题,但保留它尊重好的答案。
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.
发布评论
评论(1)
您有三个点应该位于高斯曲线上;这意味着它们位于函数上:
如果你取这个函数的对数,你会得到:
这只是一个简单的二级多项式,即具有模拟垂直轴的抛物线:
与
所以,如果知道了抛物线的三个系数,就可以推导出高斯曲线的参数;顺便说一句,您感兴趣的高斯函数的唯一参数是b,因为它告诉您分布的中心在哪里,即它的最大值在哪里。立即发现
剩下要做的就是拟合抛物线(与“原始“ x 和你的值的对数)。现在,如果您有更多点,则将涉及多项式拟合,但是,由于您只有三个点,因此情况非常简单:只有一条抛物线经过三个点。
现在,您只需为每个点写出抛物线方程并求解系统:
(使用 ,其中 z 是在相应 x 处读取的实际值)
这可以手动解决(使用一些时间),使用一些 CAS 或... 查看 StackOverflow :) ;因此,解为:
所以使用最后的方程(记住:y< /i>s 是“真实”值的对数)和其他关系,您可以轻松编写一个简单的代数公式来获取高斯曲线的参数 b,即其最大值。
(我可能在计算中做了一些混乱,在使用结果之前仔细检查它们,无论如何程序应该是正确的)
(感谢 http://www.codecogs.com/latex/eqneditor.php 用于 LaTeX 方程)
You have three points that are supposed to be on a Gaussian curve; this means that they lie on the function:
If you take the logarithm of this function, you get:
which is just a simple 2nd grade polynomial, i.e. a parabola with a vertical axis of simmetry:
with
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
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:
(with , 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:
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.
(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)