【发布时间】:2012-09-22 03:39:21
【问题描述】:
我有一个 Python 点列表(x/y 坐标):
[(200, 245), (344, 248), (125, 34), ...]
它表示二维平面上的轮廓。我想使用一些 numpy/scipy 算法进行平滑、插值等。它们通常需要 numpy 数组作为输入。例如scipy.ndimage.interpolation.zoom。
从我的点列表中获取正确的 numpy 数组的最简单方法是什么?
编辑:我在我的问题中添加了“图像”一词,希望现在清楚,如果它在某种程度上具有误导性,我真的很抱歉。我的意思的例子(指向二进制图像数组)。
输入:
[(0, 0), (2, 0), (2, 1)]
输出:
[[0, 0, 1],
[1, 0, 1]]
此处接受的答案是工作示例:
import numpy as np
coordinates = [(0, 0), (2, 0), (2, 1)]
x, y = [i[0] for i in coordinates], [i[1] for i in coordinates]
max_x, max_y = max(x), max(y)
image = np.zeros((max_y + 1, max_x + 1))
for i in range(len(coordinates)):
image[max_y - y[i], x[i]] = 1
【问题讨论】:
-
numpy.array(your_list)可能是一个好的开始...? -
不是一个开始...但真正的意思是代表无论如何...