寻找 C/C++使用离散值计算高斯曲线最大值的库

发布于 2024-11-29 23:21:04 字数 228 浏览 1 评论 0 原文

我有一些离散值和假设,这些值位于高斯曲线上。 应该有一个仅使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花随流水 2024-12-06 23:21:04

您有三个点应该位于高斯曲线上;这意味着它们位于函数上:

generic Gaussian function

如果你取这个函数的对数,你会得到:

高斯函数的对数

这只是一个简单的二级多项式,即具有模拟垂直轴的抛物线:

“通用二阶多项式”

coefficientDefinitions

所以,如果知道了抛物线的三个系数,就可以推导出高斯曲线的参数;顺便说一句,您感兴趣的高斯函数的唯一参数是b,因为它告诉您分布的中心在哪里,即它的最大值在哪里。立即发现

b from beta and alpha

剩下要做的就是拟合抛物线(与“原始“ x 和你的值的对数)。现在,如果您有更多点,则将涉及多项式拟合,但是,由于您只有三个点,因此情况非常简单:只有一条抛物线经过三个点。

现在,您只需为每个点写出抛物线方程并求解系统:

三点系统

(使用 y 和 z,其中 z 是在相应 x 处读取的实际值)

这可以手动解决(使用一些时间),使用一些 CAS 或... 查看 StackOverflow :) ;因此,解为:

三点抛物线解

所以使用最后的方程(记住:y< /i>s 是“真实”值的对数)和其他关系,您可以轻松编写一个简单的代数公式来获取高斯曲线的参数 b,即其最大值。

final result

(我可能在计算中做了一些混乱,在使用结果之前仔细检查它们,无论如何程序应该是正确的)

(感谢 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:

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文