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>Simply use the <a href="http://pillow.readthedocs.io/en/3.4.x/reference/Image.html#PIL.Image.Image.split" rel="nofollow"><code>.split()</code></a> method to split the image into different channels (called <em>bands</em> in PIL). No need to use numpy.</p>

<pre><code>(y, cb, cr) = ycbcr.split()
# y, cb and cr are all in "L" mode. 
</code></pre>

<p>After you have done the transformations, use <a href="http://pillow.readthedocs.io/en/3.4.x/reference/Image.html#PIL.Image.merge" rel="nofollow"><code>PIL.Image.merge()</code></a> to combine them again.</p>

<pre><code>ycbcr2 = im.merge('YCbCr', (y, cb, cr))
</code></pre>

python python-imaging-library color-space