change a range of colors to white in python
Question: I use following code to change specific colors (grays) to white in photos. But
the code is too slow. any suggestion or alternative is welcomed.

    
    
    import os
    import numpy as np
    from PIL import Image
    for j in range(1,160):
        im = Image.open(str(j)+'.jpg')
        data = np.array(im)
        for i in (range(205,254)):
            r1, g1, b1 = i, i, i # Original 
            r2, g2, b2 = 255, 255, 255 # Replacement
    
            red, green, blue = data[:,:,0], data[:,:,1], data[:,:,2]
            mask = (red == r1) & (green == g1) & (blue == b1)
            data[:,:,:3][mask] = [r2, g2, b2]
    
            im = Image.fromarray(data)
            im.save(os.getcwd()+'\\conv\\'+str(j)+'.jpg')
    


Answer: This way of image processing is slow because it is single threaded, and
straightforward. Try splitting it into multiple equal parts, and running them
at the same time for a major speedup (try to split the job with function and
check the results: more of smaller chunks vs lesser number of larger ones).
For greater improvement: GPU supported image manipulating, but it's quite hard
in Python.

