3x3 窗口中的插值峰值定位

发布于 2024-10-18 04:58:32 字数 182 浏览 1 评论 0原文

我正在使用 C++ 创建一个程序来查找数组中峰值的子像素位置。目前我在 3x3 窗口内找到最大值,这样每个窗口中的中心像素都大于其 8 个邻居中的每一个。

是否有一种众所周知的方法来确定峰值到亚像素精度的位置?

我读过有关通过泰勒展开式表示数组直至二次项并在零处取导数以找到偏移量的内容,但它似乎有点重量级......

I'm using C++ to create a program to find the sub-pixel location of peaks in an array. Currently I find maxima within a 3x3 window, such that the central pixel in each window is greater than each of it's 8 neighbours.

Is there a well known method for determining the location of the peak to sub-pixel accuracy?

I've read about representing the array by a Taylor expansion up to quadratic terms and taking its derivative at zero to find the offset, but it seems a little heavyweight...

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

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

发布评论

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

评论(2

萌梦深 2024-10-25 04:58:32

谢谢@罗斯。这是我为完成这项工作而编写的代码片段,以防其他人正在寻找相同的东西。

//
// By approximating with Taylor expansion to quadratic terms, the peak should
// lie at offset [ix,iy] from as calculated by:
//
//   [ix]  =  - [d2I/dx2  d2I/dxy]^-1 . [dI/dx]
//   [iy]       [d2I/dxy  d2I/dy2]      [dI/dy]
//
//
// Assume 'arr' is our array of values (i.e. image) and [x,y] is the location of 
// of a peak pixel in the array.  The interpolated location of the peak is given 
// by the point [x+ix][y+iy].
//

float dx = (arr[x+1][y] - arr[x-1][y]) / 2.f;
float dy = (arr[x][y+1] - arr[x][y-1]) / 2.f;
float dxx = (arr[x+1][y] + arr[x-1][y] - 2 * arr[x][y]);
float dyy = (arr[x][y+1] + arr[x][y-1] - 2 * arr[x][y]);
float dxy = (arr[x+1][y+1] - arr[x+1][y-1] - arr[x-1][y+1] + arr[x-1][y-1]) / 4.f;

float det = 1.f/(dxx*dyy - dxy*dxy);

float ix = x - (dyy*dx - dxy*dy) * det;
float iy = y - (dxx*dy - dxy*dx) * det;

Thanks @Ross. Here's a code snippet of what I wrote to do the job in case anyone else is looking for the same thing.

//
// By approximating with Taylor expansion to quadratic terms, the peak should
// lie at offset [ix,iy] from as calculated by:
//
//   [ix]  =  - [d2I/dx2  d2I/dxy]^-1 . [dI/dx]
//   [iy]       [d2I/dxy  d2I/dy2]      [dI/dy]
//
//
// Assume 'arr' is our array of values (i.e. image) and [x,y] is the location of 
// of a peak pixel in the array.  The interpolated location of the peak is given 
// by the point [x+ix][y+iy].
//

float dx = (arr[x+1][y] - arr[x-1][y]) / 2.f;
float dy = (arr[x][y+1] - arr[x][y-1]) / 2.f;
float dxx = (arr[x+1][y] + arr[x-1][y] - 2 * arr[x][y]);
float dyy = (arr[x][y+1] + arr[x][y-1] - 2 * arr[x][y]);
float dxy = (arr[x+1][y+1] - arr[x+1][y-1] - arr[x-1][y+1] + arr[x-1][y-1]) / 4.f;

float det = 1.f/(dxx*dyy - dxy*dxy);

float ix = x - (dyy*dx - dxy*dy) * det;
float iy = y - (dxx*dy - dxy*dx) * det;
睫毛溺水了 2024-10-25 04:58:32

如果这对你来说似乎是“重量级”,那么一切都是重量级的。一般来说,您需要一种插值算法来从离散表示变为某种连续表示并找到峰值。使用“图像处理”意味着 2D 功能。我可以建议使用一些基本插值(线性、双线性、三次等)并找到导数趋于 0 的峰值。

If this seems "heavyweight" for you everything is heavyweight. Generally speaking you need a interpolation algorithm to get from discrete representation to some continuous representation and find the peak. Using "image-processing" implies functions in 2D. I can suggest to use some basic interpolation (linear, bi-linear, cubic, etc.) and find the peaks where derivatives go to 0.

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