Fun with P(h)IL

Have you ever tried to convert BGR image to RGB image.

Of course, this can be done by giong back and forth between scipy and PIL, and shuffling the channals in between.

scipyimg = scipy.misc.pilutil.fromimage(pilimg)
scipyimg = scipy.asarray(pilimg)
pilimg = Image.fromarray(scipyimg, 'RGB')

But there is also a more direct way to do it. Let’s try:

B,G,R = pilimg.split()
pilimg = Image.merge("RGB",(R,G,B))

Funny,

b,g,r = pilimg.split()

sometimes (but, just sometimes) throws an error like this:

*** The specified object ',g,r = pilimg.split()' is not a function