[Image-SIG] problem with putdata function

Cai Xiao(dynaturtle) dynaturtle.cai at gmail.com
Tue May 12 14:46:06 CEST 2009


Thanks for your suggestion. And I find where the problem is.

On Tue, May 12, 2009 at 8:44 PM, Fredrik Lundh <fredrik at pythonware.com>wrote:

> On Tue, May 12, 2009 at 7:11 AM, Cai Xiao(dynaturtle)
> <dynaturtle.cai at gmail.com> wrote:
> > Hey, I am new to PIL. And I have a problem with putdata function when I
> try
> > to load some data to the image object
> > The code is as following:
> >
> >     mode = 'RGB'
> >     size = (sregion.right - sregion.left, sregion.top - sregion.bottom)
> >     im = Image.new(mode, size)
> >
> >     if type == 'dem':
> >         minV = band.GetMinimum()
> >         maxV = band.GetMaximum()
> >         imData = []
> >         for j in range(size[1]):
> >             for i in range(size[0]):
> >                 heightValue = int((rasterTuple[i * size[0] + j] - minV) *
> > 255 / (maxV - minV))
> >                 pixelValue = (i,j,heightValue)
> >                 imData.append(pixelValue)
> >
> >         im.putdata(imData)
> >
> >     I got a error when the program run to line 15, the error information
> is
> > as following:
> >           OverflowError: 'long int too large to convert to int'
> >     the imData length is 981760, and my computer memory is 2GB
>
> This means that you have pixels with RGB values bigger than 255 (and
> unless you've hit a buglet, they're a *lot* bigger than 255).
>
> Try doing this before the putdata call:
>
>    print max(pixel[0] for pixel in imData) # max red
>    print max(pixel[1] for pixel in imData) # max green
>    print max(pixel[2] for pixel in imData) # max blue
>
> and make sure the values are in the expected range.
>
> </F>
>



-- 
Department of Spatial Information Science&Technology,
School of Earth&Space Science, Peking University

ADD: Room 3028, Building 46, Peking University, Beijing, P.R. China
Zip Code: 100871
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090512/207d18a3/attachment.htm>


More information about the Image-SIG mailing list