Python Imaging: YCbCr problems
- by daver
Hi, I'm doing some image processing in Python using PIL, I need to extract the luminance layer from a series of images, and do some processing on that using numpy, then put the edited luminance layer back into the image and save it. The problem is, I can't seem to get any meaningful representation of my Image in a YCbCr format, or at least I don't understand what PIL is giving me in YCbCr. PIL documentation claims YCbCr format gives three channels, but when I grab the data out of the image using np.asarray, I get 4 channels. Ok, so I figure one must be alpha.
Here is some code I'm using to test this process:
import Image as im
import numpy as np
pengIm = im.open("Data\\Test\\Penguins.bmp")
yIm = pengIm.convert("YCbCr")
testIm = np.asarray(yIm)
grey = testIm[:,:,0]
grey = grey.astype('uint8')
greyIm = im.fromarray(grey, "L")
greyIm.save("Data\\Test\\grey.bmp")
I'm expecting a greyscale version of my image, but what I get is this jumbled up mess:
http://i.imgur.com/zlhIh.png
Can anybody explain to me where I'm going wrong? The same code in matlab works exactly as I expect.