image.toarray method generates wrong shape array for YCbCr images

Bug #656666 reported by David Coles
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-imaging
Fix Committed
Undecided
auto-image-sig
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://svn.effbot.python-hosting.com/pil/PIL/Image.py.

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 incorrectly:

>>> 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', ycbcr.tostring())
>>> print B.shape
(360, 640, 3)
>>> im.fromarray(B[:,:,0], "L").show()

ProblemType: Bug
DistroRelease: Ubuntu 10.10
Package: python-imaging 1.1.7-2
ProcVersionSignature: Ubuntu 2.6.35-22.33-generic 2.6.35.4
Uname: Linux 2.6.35-22-generic x86_64
NonfreeKernelModules: nvidia
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

Revision history for this message
David Coles (dcoles) wrote :
Revision history for this message
David Coles (dcoles) wrote :

Attached is a patch against 1.1.7-2 (python-imaging) (since there appears to be no development repository).

Revision history for this message
David Coles (dcoles) wrote :
Changed in python-imaging (Ubuntu):
status: New → Confirmed
Revision history for this message
David Coles (dcoles) wrote :

Mailed patch and report to the Python-Imaging thread: http://mail.python.org/pipermail/image-sig/2010-October/006526.html

Revision history for this message
David Coles (dcoles) wrote :

"Just committed a fix to trunk (including some simple tests for this
operation & mode...). Thanks! /F"
    -- http://mail.python.org/pipermail/image-sig/2010-November/006565.html

Fix committed. Now just have to wait for the next release of PIL...

Changed in python-imaging:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

  • auto-image-sig Edit

Bug watches keep track of this bug in other bug trackers.