Let there be two big (2000x2000 or higher) .tiff images consisting only of numpy float32 values (no rgb). I call them Image A and B. I want to multiply them in a special way:
- Find the max value in B and roll it (using numpy.roll) to the upper-left most corner.
- Multiply A and B
- Add the sum of B to the index of A where the max value of B was rolled
- Roll the max of B one element further
- Repeat for all elements of A
- save the resulting image
Both images are always the same shape. I've come up with this idea:
#A,B are loaded with PIL as numpy images and are flattend
B = np.roll(B, len(mult_img)-distance_to_max) #roll max to the first element
sum_arr = np.sum(B) #sum of B
for i in range(len(A)):
A = np.multiply(A, np.roll(B, i)) #roll B with i-increment and multiply
A[i] += sum_arr #add sum to A at index
This looks like it would do the job, after reshaping the array and save it. But it takes about 40s for a 2000x2000 image and there will be hundrets of them to process. Question is: how can this be improved? or are there better numpy solutions for this task to speed things up a bit?
Thanks in advance