I have following question about faster way to compute rigid transformation (yes, I know I can simply use library but need to code this by myself).
I need to compute x' and y' for every x,y in given image. My main bottleneck is dot product for all coordinates (interpolation after this is not a problem). Currently I implemented three options:
list comprehension
result = np.array([[np.dot(matrix, np.array([x, y, 1])) for x in xs] for y in ys])
simple double-
for
loopresult = np.zeros((Y, X, 3)) for x in xs: for y in ys: result[y, x, :] = np.dot(matrix, np.array([x, y, 1]))
np.ndenumerate
result = np.zeros((Y, X, 3)) for (y, x), value in np.ndenumerate(image): result[y, x, :] = np.dot(matrix, np.array([x, y, 1]))
The fastest way in 512x512 images is list comprehension (about 1.5x faster than np.ndenumerate
and 1.1x faster than double for loop).
Is there any way to do this faster?