我尝试做的事情,应该是没有什么比二维,线性插值但目前我不找到正确的方法。为了说明这个问题有点简单:没有与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乘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?
推荐答案
您必须同意对插值方法第一。我建议无论是双线性或重心插值。在我的previous帖子之一我可视化这两种方法之间的差异。
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.
我们需要插补参数 U
和 v
的点(X,Y )
。因为我们有一个轴对齐网格,这是pretty的简单:
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)
现在,相同的公式可以用于校正的点。如果您使用原始分 P1
到 P4
,你会得到裸线点。如果通过 P4
使用校正细胞分 P1
,你会得到纠正线点。
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.
相关推荐
最新文章