Вы можете разделить изображение на несколько multiprocess.Array
, обработать каждое из них по отдельности, а затем реконструировать изображение.
Вот несколько примеров игрушек, с которых можно начать:
from multiprocessing import Process, Lock
from multiprocessing.sharedctypes import Value, Array
import numpy as np
def processBlock(arr,i): #Image Processing function, i is an extra argument i used for the process.
block = np.frombuffer(arr.get_obj())
block = block.reshape((512,512,3))
#Some processing
block[:] = i
############
block = block.reshape((-1))
arr[:] = block
fullImage = np.zeros((512*2,512*2,3)) #Create full image of 0s
imageParts = []
imageParts.append(Array('d',fullImage[0:512,512:,:].flatten())) #Divide it into 4 parts
imageParts.append(Array('d',fullImage[0:512,0:512,:].flatten()))
imageParts.append(Array('d',fullImage[512:,0:512,:].flatten()))
imageParts.append(Array('d',fullImage[512:,512:,:].flatten()))
processes = []
for i in range(4): #Process each part simulatinously
p = Process(target = processBlock, args=(imageParts[i],i))
p.start()
processes.append(p)
for i in range(4): #Wait for all
processes[i].join()
#Reconstruct Image
fullImage[0:512,512:,:] = np.frombuffer(imageParts[0].get_obj()).reshape((512,512,3))
fullImage[0:512,0:512,:] = np.frombuffer(imageParts[1].get_obj()).reshape((512,512,3))
fullImage[512:,0:512,:] = np.frombuffer(imageParts[2].get_obj()).reshape((512,512,3))
fullImage[512:,512:,:] = np.frombuffer(imageParts[3].get_obj()).reshape((512,512,3))