arr = arr.astype('float')
for i in range(3):
    minval = arr[..., (i)].min()
maxval = arr[..., (i)].max()
if minval != maxval:
    arr[..., (i)] -= minval
arr[..., (i)] *= 255.0 / (maxval - minval)
return arr

def demo_normalize():
    img = Image.open(FILENAME).convert('RGBA')
arr = np.array(img)
new_img = Image.fromarray(normalize(arr).astype('uint8'), 'RGBA')
new_img.save('/tmp/normalized.png')
Intensity normalization of image using Python+PIL - Speed issues