线性插补:根据二维表计算修正 [英] Linear interpolation: calculate correction based on 2D table

查看:30
本文介绍了线性插补:根据二维表计算修正的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试做的事情应该只是二维线性插值,但目前我找不到正确的方法.为了简单地描述这个问题:有一个大小为 3000x3000 像素的绘图区域,我必须在其中绘制,例如一条水平线.为此,我从每个像素位置到下一个像素位置绘制点或短线,然后形成一条线.

I try to do a thing that should be nothing more than a two-dimensional, linear interpolation but currently I fail finding the correct approach. To describe the problem a bit simplified: there is a drawing area with a size of 3000x3000 pixels where I have to draw e.g. a horizontal line. To do that I'm drawing dots or short lines from every pixel position to the next pixel position which then forms a line.

现在必须对整个事物应用更正,其中可以在(对于此示例简化)4 x 4 数组中找到更正信息,其中每个元素都包含描述更正后值的一对坐标.所以一个中性数组(没有修正)看起来像这样:

Now a correction has to be applied to the whole thing where correction information can be found in a (for this example simplified) 4 by 4 array, where every element contains a pair of coordinates describing the values after correction. So a neutral array (with no correction) would look like this:

0,0      1000,0      2000,0      3000,0
0,1000   1000,1000   2000,1000   3000,1000
0,2000   1000,2000   2000,2000   3000,2000
0,3000   1000,3000   2000,3000   3000,3000

一个真正的校正表将包含描述要完成的校正的其他坐标:

A real correction table would contain other coordinates describing the correction to be done:

因此,作为输入数据,我有未经校正的线上点的坐标、未经校正的字段值和校正数据.但是,我现在如何计算线点,然后将校正值应用于它,以便绘制扭曲的线,如图像右侧所示?我目前对 X 和 Y 使用两个单独的线性插值的方法不起作用,Y 位置在单元格边界上跳跃,但在单元格内没有平滑变化.

So as input data I have the coordinates of points on the line without correction, the fields values without correction and the correction data. But how can I calculate the lines points now applying the correction values to it so that a distorted line is drawn like shown in right side if the image? My current approach with two separate linear interpolations for X and Y does not work, there the Y-position jumps on a cells border but does not change smoothly within a cell.

那么……有什么想法可以做到吗?

So...any ideas how this could be done?

推荐答案

您必须首先就插值方法达成一致.我会建议双线性或重心插值.在我之前的一篇博文中,我想象了两种方法之间的区别.

You have to agree on an interpolation method first. I would suggest either bilinear or barycentric interpolation. In one of my previous posts I visualized the difference between both methods.

我将专注于双线性插值.我们想将单元格内的任何点转换为其校正点.因此,所有点都可以单独变换.

I'll concentrate on the bilinear interpolation. We want to transform any point within a cell to its corrected point. Therefore, all points could be transformed separately.

我们需要点(x, y)的插值参数uv.因为我们有一个轴对齐的网格,所以这很简单:

We need the interpolation parameters u and v for the point (x, y). Because we have an axis-aligned grid, this is pretty simple:

u = (x - leftCellEdge) / (rightCellEdge - leftCellEdge)
v = (y - bottomCellEdge) / (topCellEdge - bottomCellEdge)

我们可以通过双线性插值重建点:

We could reconstruct the point by bilinear interpolation:

p2       p4
   x----x
   |  o |
   x----x
p1       p3

o = (1 - u) * ((1 - v) * p1 + v * p2) + u * ((1 - v) * p3 + v * p4)

现在,相同的公式可用于校正点.如果使用原始点p1p4,您将得到未校正的线点.如果您使用 p1p4 的更正单元格点,您将获得更正的线点.

Now, the same formula can be used for the corrected points. If you use the original points p1 through p4, you'll get the uncorrected line point. If you use the corrected cell points for p1 through p4, you'll get the corrected line point.

这篇关于线性插补:根据二维表计算修正的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆