[Image-SIG] problem with putdata function

Fredrik Lundh fredrik at pythonware.com
Tue May 12 14:44:12 CEST 2009


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>


More information about the Image-SIG mailing list