简体   繁体   English

并行映射2D python数组

[英]map 2D python array in parallel

I can scatter the pixels in an image according to a 1D map of tuples containing the old x,y coordinate of each pixel 我可以根据包含每个像素的旧x,y坐标的元组的一维映射来分散图像中的像素

Is there a way to do this faster such as using multiple CPU coords or otherwise? 有没有办法更快地执行此操作,例如使用多个CPU坐标?

i=0
for x in range(1080)
    for y in range(720)
        result_img_arr[x][y] = input_img_arr[map_tuples[i]]
        i+=1

input_img_arr - An image array with the shape (1080, 720, 3) input_img_arr-形状为(1080,720,3)的图像数组

map_tuples - 1D array of tuples with length (1080*720) containing x,y the coordinates to read from input image map_tuples-一维元组数组,长度为(1080 * 720),包含要从输入图像读取的x,y坐标

Don't know about parallel-processing, but using a list-comprehension should definitely improve the speed. 不了解并行处理,但是使用list-comprehension绝对可以提高速度。 Something on the lines... 线路上的东西...

result_img_arr = [[map_tuples[y + x*720] 
                       for y in range(720)] 
                           for x in range(1080)]

autojit with numba should speed that up considerably. 使用numba的autojit应该可以大大加快速度。 And if that's still not enough you can take a look at pyopencl, but that can be a bit complicated to get right. 如果还不够,您可以看看pyopencl,但这可能有点复杂。

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

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