PIL's Image class has incorrect dimension specified for YCbCr images.
This causes issues when converting to or from NumPy arrays.

According to http://www.pythonware.com/library/pil/handbook/concepts.htm
YCbCr should be "3x8-bit pixels, colour video format". Instead it
appears to be converted to a 4x8-bit format.

The incorrect definition is at line 206 of

Example: Load up any image and convert to YCbCr.
import numpy
import Image as im
image = im.open('bush640x360.png')
ycbcr = image.convert('YCbCr')
Using the Array interface produces a HxWx4 array, which is the wrong
dimensions for YCbCr. Thus when selecting a single channel it displays
A = numpy.asarray(ycbcr)
print A.shape
(360, 640, 4)
im.fromarray(A[:,:,0], "L").show()
Here's an example decoding the image byte string ourselves gives the
correct result:
B = numpy.ndarray((image.size[1], image.size[0], 3), 'u1',
print B.shape
(360, 640, 3)
im.fromarray(B[:,:,0], "L").show()
Attached is a patch against the 1.1.7-2 (python-imaging) package in
Ubuntu as I can't find the development repository for 1.1.7. See
https://bugs.edge.launchpad.net/ubuntu/+source/python-imaging/+bug/656666 for details.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PIL-ycbcr.patch
Type: text/x-patch
Size: 325 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20101008/31ff4139/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/image-sig/attachments/20101008/31ff4139/attachment.pgp>

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post

2 users in discussion

David Coles: 2 posts Fredrik Lundh: 2 posts



site design / logo © 2016 Grokbase