Save Different Channels of Ycbcr as seperate images | Python
<p>I need to apply some transformations to the individual channels of the Ycbcr color space.</p>

<p>I have an tiff format image as the source and I need to convert it to ycbcr color space. I have not been able to successfully save the different channels as separate images. I have been only able to extract the luminescence channel using this code:</p>

<pre><code>import numpy
import Image as im
image = im.open('1.tiff')
ycbcr = image.convert('YCbCr')

B = numpy.ndarray((image.size[1], image.size[0], 3), 'u1', ycbcr.tobytes())
im.fromarray(B[:,:,0], "L").show()
</code></pre>

<p>Can someone pls help.</p>

<p>Thank you </p>

<p>Here is my code:</p>

<pre><code>import numpy
import Image as im
image = im.open('1.tiff')
ycbcr = image.convert('YCbCr')

# output of ycbcr.getbands() put in order
Y = 0
Cb = 1
Cr = 2

YCbCr=list(ycbcr.getdata()) # flat list of tuples
# reshape
imYCbCr = numpy.reshape(YCbCr, (image.size[1], image.size[0], 3))
# Convert 32-bit elements to 8-bit
imYCbCr = imYCbCr.astype(numpy.uint8)

# now, display the 3 channels
im.fromarray(imYCbCr[:,:,Y], "L").show()
im.fromarray(imYCbCr[:,:,Cb], "L").show()
im.fromarray(imYCbCr[:,:,Cr], "L").show()
</code></pre>

python python-imaging-library color-space