[Image-SIG] problem with numpy.asarray and PIL

Gary Capell gary.capell at gmail.com
Tue Aug 4 07:07:18 CEST 2009


2009/8/4 Guy K. Kloss <g.kloss at massey.ac.nz>

> On Mon, 27 Jul 2009 19:08:16 Gary Capell wrote:
> > I get this problem (with python2.6, PIL 1.1.6, numpy 1.3.0 )
> >
> > >>> from PIL import Image
> > >>> import numpy
> > >>> i = Image.open('chart_bl.tif')
> > >>> a = numpy.asarray(i)
> > >>> o.size, a.shape
> > ((13228, 18710), (18710, 13228))
> > >>> o.size, a.shape, a.dtype
> > ((13228, 18710), (18710, 13228), dtype('bool'))
> > >>> numpy.histogram(a)
> > Segmentation fault
>
> I'm assuming your image is a binary (black and white only) image. In that
> case
> histogramming doesn't make much sense. If you want the numbers of ones and
> zeros, just do something like that:
>
> ones = a.sum()
> zeros = a.shape[0] * a.shape[1] - ones
>
>
I'm OK with the operation not making much sense, I'm not OK with python
dying with a segmentation fault.

For what it's worth, I also get a segfault with a.sum():

>>> i = Image.open('/tmp/chart_bl.tif')
>>> a = numpy.asarray(i)
>>> a.sum()
Segmentation fault
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090804/ce030020/attachment.htm>


More information about the Image-SIG mailing list