[Scipy-tickets] [SciPy] #1613: scipy.misc.imread segfaults on 1 bit png

SciPy Trac scipy-tickets@scipy....
Thu Mar 1 14:14:52 CST 2012

#1613: scipy.misc.imread segfaults on 1 bit png
 Reporter:  wiredfool        |       Owner:  somebody    
     Type:  defect           |      Status:  needs_review
 Priority:  normal           |   Milestone:  0.11.0      
Component:  scipy.misc       |     Version:  0.8.0       
 Keywords:  imread segfault  |  
Changes (by wiredfool):

  * status:  new => needs_review


 First, 1205 is similar. It's probably the same underlying bug.

 3 differences though:
   * I've determined that it's a 1 bit image issue.
   * This is a scipy method call that's crashing (at least from the POV of
 my code), not some combination of PIL and scipy. (though, under the
 covers, it's the same)
 import scipy
 f = scipy.misc.imread('test/horiz_stripe_front.png')
 Segmentation fault
   * There's a really simple fix:
 def fromimage(im, flatten=0):
     Return a copy of a PIL image as a numpy array.

     im : PIL image
         Input image.
     flatten : bool
         If true, convert the output to grey-scale.

     img_array : ndarray
         The different colour bands/channels are stored in the
         third dimension, such that a grey-image is MxN, an
         RGB-image MxNx3 and an RGBA-image MxNx4.

     if not Image.isImageType(im):
         raise TypeError("Input is not a PIL image.")
     if flatten:
         im = im.convert('F')
 +   elif img.mode='1':
 +      img.convert('L')
     return array(im)

Ticket URL: <http://projects.scipy.org/scipy/ticket/1613#comment:4>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list