[Image-SIG] problem with putdata function
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):
> for i in range(size):
> heightValue = int((rasterTuple[i * size + j] - minV) *
> 255 / (maxV - minV))
> pixelValue = (i,j,heightValue)
> 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 for pixel in imData) # max red
print max(pixel for pixel in imData) # max green
print max(pixel for pixel in imData) # max blue
and make sure the values are in the expected range.
More information about the Image-SIG