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

Guy K. Kloss g.kloss at massey.ac.nz
Tue Aug 4 07:01:17 CEST 2009


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

HTH,

Guy


-- 
Guy K. Kloss
Institute of Information and Mathematical Sciences
Te Kura Pūtaiao o Mōhiohio me Pāngarau
Massey University, Albany (North Shore City, Auckland)
473 State Highway 17, Gate 1, Mailroom, Quad B Building
voice: +64 9 414-0800 ext. 9585   fax: +64 9 441-8181
G.Kloss at massey.ac.nz http://www.massey.ac.nz/~gkloss


More information about the Image-SIG mailing list