Hi, I have a 3D-array from an image in Numpy (4096, 8192, 3), with 4096 rows, 8192 colmuns with each cell being a list [RED, GREEN, BLUE]
When I want to extract all cells with the same RGB value I use mask = numpy.all(image == (R,G,B), axis=-1) then I can use image[mask] to modify the pixels I filtered for.
My issue is I need to do this around 9600 times and each time takes ~2 seconds.
I'm looking for ways to speed up the process.
I've tried multi-processing but that only reduced the time from 5 hours to around 3.
Currently I'm thinking of reusing the mask for the next filter so it skips pixels I've already checked before, but I'm having trouble implementing as its a 2-D array instead of a 3-D one.
new_mask = numpy.all(~mask & (province_map == filter_array), axis=-1) returns me the error operands could not be broadcast together with shapes (4096,8192) (4096,8192,3)