[SciPy-User] fromimage/imread segfaults on my images

Daniel Lenski dlenski at gmail.com
Mon Mar 8 22:26:14 EST 2010


On Mon, 08 Mar 2010 11:58:08 -0800, Christopher Barker wrote:

> Daniel Lenski wrote:
>> I'm using SciPy to process some sparse binary images with a resolution
>> of about 5000x5000 pixels.  I try to load images like this:
>> 
>>   im = Image.open('/tmp/foo.pbm')
>>   print "Image loaded, size is %s and mode is %s." % (im.size, im.mode)
>>   arr = fromimage(im)
>> 
>> or
>> 
>>   arr = imread('/tmp/foo.pbm')
> 
> where do fromimage and imread come from? "namespaces are one honking
> great idea".

Sorry! That'd be

  from scipy.misc import fromimage, imread

> don't be so sure -- I think PIL used lazy loading, so it doesn't
> actually read all the data with the open call, but rather when you try
> to do something with it.
> 
> I'd try making a few calls on the PIl image, and make sure it is what
> you expect. If it is, the easiest way to get it into a numpy array is:

True, PIL lazy-loads the image.  However, I've checked this, and I'm able 
to manipulate the image via PIL with no problems.

> np.asarray(pil_image)

Yeah, I looked at the scipy.misc.fromimage code and this is all it does, 
basically.

> do you have a smaller image in the same format you can experiment with?
> That might make it easier to figure out.

Yes, smaller images in the same format work fine!

>>  I don't know any other good, reliable way
>> to get a big image into an array :-(
> 
> if you really can't get PIL to work, pbm looks really simple:
> 
> http://netpbm.sourceforge.net/doc/pbm.html
> 
> read the header, then read the data with np.fromfile(), then convert to
> a uint8 array with np.unpackbits().

That's what I've ended up doing...
 
> You could also take a look at MPL's imread() and see what it does -- I
> don't think MPL requires PIL, though I could be wrong.

MPL does require PIL for formats other than PNG.

Dan





More information about the SciPy-User mailing list