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

Christopher Barker Chris.Barker@noaa....
Mon Mar 8 13:58:08 CST 2010

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".

> In either case, I get a segfault.  The segfault is definitely in the 
> SciPy code, rather than the PIL code, since PIL's Image.open runs fine. 

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:


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

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


read the header, then read the data with np.fromfile(), then convert to 
a uint8 array with np.unpackbits().

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.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the SciPy-User mailing list