[Image-SIG] problem with putdata function
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
> > 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)
> > imData.append(pixelValue)
> > im.putdata(imData)
> > I got a error when the program run to line 15, the error information
> > 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.
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...
More information about the Image-SIG