image.toarray method generates wrong shape array for YCbCr images
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-imaging |
Fix Committed
|
Undecided
|
|||
python-imaging (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: python-imaging
PIL's Image class has incorrect dimension specified for YCbCr images. This causes issues when converting to or from NumPy arrays.
The incorrect definition is at line 206 of http://
Example: Load up any image and convert to YCbCr.
>>> import numpy
>>> import Image as im
>>> image = im.open(
>>> ycbcr = image.convert(
Using the Array interface produces a HxWx4 array, which is the wrong dimensions for YCbCr. Thus when selecting a single channel it displays incorrectly:
>>> A = numpy.asarray(
>>> print A.shape
(360, 640, 4)
>>> im.fromarray(
Here's an example decoding the image byte string ourselves gives the correct result:
>>> B = numpy.ndarray(
>>> print B.shape
(360, 640, 3)
>>> im.fromarray(
ProblemType: Bug
DistroRelease: Ubuntu 10.10
Package: python-imaging 1.1.7-2
ProcVersionSign
Uname: Linux 2.6.35-22-generic x86_64
NonfreeKernelMo
Architecture: amd64
Date: Fri Oct 8 14:58:29 2010
EcryptfsInUse: Yes
InstallationMedia: Ubuntu 10.04.1 LTS "Lucid Lynx" - Release amd64 (20100816.1)
ProcEnviron:
PATH=(custom, user)
LANG=en_AU.utf8
SHELL=/bin/bash
SourcePackage: python-imaging
Attached is a patch against 1.1.7-2 (python-imaging) (since there appears to be no development repository).