I have an image where the colors are BGR. How can I transform my PIL image to swap the B and R elements of each pixel in an efficient manner?
Just a quick footnote for anyone writing code that might have to deal with 4-channel images, and discovering that the simple numpy answer seems to be eating their alpha channel.
np_image[:,:,[0,1,2]] = np_image[:,:,[2,1,0]]
will preserve the alpha data if there is a fourth channel, whereas
np_image = np_image[:,:,[2,1,0]]
will overwrite the 4-channel image with only reversed 3-channel data. (And the even simpler numpy answer, img = img[:,:,::-1], will give you ARGB data, which would be bad, too. :)