简体   繁体   English

网格python的不规则点

[英]irregular points to grid python

I am having a bit of trouble trying to transform 2D irregular points into a grid in Python. 我在尝试将2D不规则点转换为Python中的网格时遇到了一些麻烦。

As a bit of background, I have calculated average x,y position of a eye tracking data and am trying to devise some (higher order/polynomial) function to transform these points to a grid with 'real' position in space. 作为背景知识,我已经计算了眼睛跟踪数据的平均x,y位置,并尝试设计一些(高阶/多项式)函数将这些点转换为空间中具有“真实”位置的网格。 In the figure below, I am trying to take the average x,y positions of the eye tracking data (shown in black) and trying to project them to the 'known' x,y positions for the grid (shown in red) 在下图中,我试图获取眼睛跟踪数据的平均x,y位置(以黑色显示),并尝试将其投影到网格的“已知” x,y位置(以红色显示)

Averaged Data (Black), Desired Grid Points (Red) 平均数据(黑色),所需网格点(红色)

The raw data values are as follows: 原始数据值如下:

AvgX = [5.9249217363378444, 29.400090125634197, 189.88137522082039, 10.635691487603076, -156.27020696966224, 125.03659193723372, -168.39555447902086, 186.62552891024129, 111.90418423429169, 100.57725103088637, -76.716438908489465, 6.5688214489253474, 146.18743315136786, -77.676030038490595, 175.21590859125735, -55.931989461463523, -175.71204466459488, 97.750258696640429, 4.4562688886630015, -71.385022755147517, 191.47832859030729, -83.713605575394325, 100.81203864776603]
AvgY = [168.67521806680125, 19.421198111140864, -221.60630388937381, 79.730784050599141, 195.43389670921019, 98.926386207770904, -85.356440304228784, -39.574253598391287, 175.70610514354374, -113.76915782872061, -187.40510724928777, -86.989048811265221, -118.46908736453032, 8.054366530368533, 51.680353870737072, -81.628307614654986, 18.393403891381649, -23.678128041659768, -193.94235177110983, 100.69985383522851, 145.38153797528696, 190.0494081938453, -202.22859560880681]
GridX = [0.0, 0.0, 185.635467529, 0.0, -185.635467529, 92.8177337646, -185.635467529, 185.635467529, 92.8177337646, 92.8177337646, -92.8177337646, 0.0, 185.635467529, -92.8177337646, 185.635467529, -92.8177337646, -185.635467529, 92.8177337646, 0.0, -92.8177337646, 185.635467529, -92.8177337646, 92.8177337646]
GridY = [188.696807861, 0.0, -188.696807861, 94.3484039307, 188.696807861, 94.3484039307, -94.3484039307, 0.0, 188.696807861, -94.3484039307, -188.696807861, -94.3484039307, -94.3484039307, 0.0, 94.3484039307, -94.3484039307, 0.0, 0.0, -188.696807861, 94.3484039307, 188.696807861, 188.696807861, -188.696807861]

From my understanding, I will need to apply some sort of polynomial function to map the averaged data to the known grid. 根据我的理解,我将需要应用某种多项式函数来将平均数据映射到已知网格。 However, I am not sure how to go about this. 但是,我不确定该如何处理。

Rounding works when the averaged points (blue) are near the target grid points (red). 当平均点(蓝色)接近目标网格点(红色)时,取整工作。 However, this does not work when the averaged points are closer to an arbitrary grid point than the actual target grid point. 但是,当平均点比实际目标网格点更靠近任意网格点时,这将不起作用。 Take for example if the entire averaged grid is shifted down. 以整个平均网格向下移动为例。

Example Image . 示例图片

In this example the 1. red points are the target location 2. black points are the averaged location 3. blue points are the transform when rounded 4. orange arrows are how the averaged points are shifted with rounding 5. green arrows are how I am trying to shift the data. 在此示例中1.红色点是目标位置2.黑色点是平均位置3.蓝色点是四舍五入后的变换4.橙色箭头是平均点如何随四舍五入而移动5.绿色箭头是我如何试图转移数据。

Eventually I want to put in some random point (raw data) and apply some function to the point to reposition it to it's "actual" location given the calibration points. 最终,我想放置一些随机点(原始数据)并将某些功能应用于该点,以将其重新定位到给定校准点的“实际”位置。 I am guessing that I will need to apply some spline or higher order polynomial function across each row and column of points to produce some contour to interpolate the raw data inputs that I give this function. 我猜想我将需要在点的每一行和每一列上应用一些样条函数或高阶多项式函数,以生成一些轮廓以插值我为此函数提供的原始数据输入。

Since your grid is characterized by two numbers -- the step size in x and the step size in y -- we can apply a simple transformation that rounds the data: 由于您的网格由两个数字表示-x中的步长和y中的步长-我们可以应用一个简单的变换来对数据进行舍入:

import numpy as np

DELTA_X = 92.8177337646
DELTA_Y = 94.3484039307

def gridify(coords, spacing):
    coords = np.array(coords)
    return np.round(coords / spacing) * spacing

x = gridify(AvgX, DELTA_X)
y = gridify(AvgY, DELTA_Y)

Which gives: 这使:

在此处输入图片说明

If your grid is regular, why not just round to the nearest 100 or whatever the spacing is? 如果您的网格是规则的,为什么不将其四舍五入到最接近的100或任何间距?

Python - Round to nearest 05 Python-舍入到最接近的05

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM