【发布时间】:2022-10-05 04:48:25
【问题描述】:
为了提高效率,我想使用 numpy 对以下内容进行矢量化,但我发现很难考虑,我不知道如何开始。
import numpy as np
imageA = np.random.randint(10, size=(4, 5)) # Some image
imageB = np.random.randint(10, size=(4, 5)) # Some other image
transformation = np.random.randint(10, size=(3, 3)) # Some transformation matrix
out_image = imageB.copy()
for y in range(imageB.shape[0]):
for x in range(imageB.shape[1]):
u, v, w = transformation @ np.array([x, y, 1])
x_p, y_p = u/w, v/w
if x_p >= 0 and x_p < imageA.shape[1] and y_p >= 0 and y_p < imageA.shape[0]:
out_image[y, x] = imageA[int(y_p), int(x_p)]
【问题讨论】:
-
发布完整的测试代码以供使用。 stackoverflow.com/help/minimal-reproducible-example
标签: python numpy vectorization projection