Implementation of Multiprocessing in images

29 Views Asked by At

I am running a fisher exact test on each voxel of two images of size (240,240,155). I only have basic knowledge in multiprocessing and am unsure on how to apply it to my case.

This is the code I am trying to run:

result_array = np.zeros_like(imgRHUH, dtype=float)

for (x_RHUH,y_RHUH,z_RHUH), valueRHUH in np.ndenumerate(imgRHUH):
    for (x_BTP,y_BTP,z_BTP), valueBTP in np.ndenumerate(imgBTP):
        a = int(valueRHUH)
        b = int(valueBTP)
        c = 39 - a
        d = 20 - b
        n = 2
         
        p = (math.factorial(a + b)*math.factorial(c + d)*math.factorial(a + c)*math.factorial(b + d)) / (math.factorial(a)*math.factorial(b)*math.factorial(c)*math.factorial(d)*math.factorial(n))

        result_array[x_RHUH, y_RHUH, z_RHUH] = p

I have tried splitting the first image into chunks like this

chunks = []
for chunk in np.array_split(list(np.ndenumerate(imgRHUH)), multiprocessing.cpu_count()):
   chunks.append((chunk, imgRHUH, imgBTP, result_array))

, but this didn't seem to improve performance by much. Furthermore I am afraid that even if this end up completing it might merge the image back together in the wrong way ?

0

There are 0 best solutions below