[Image-SIG] Histograms: Bug or feature?

Jonathan M. Gilligan jonathan.gilligan@vanderbilt.edu
Tue, 09 Jan 2001 15:37:19 -0600


If img is an image with mode='I' (i.e., 32-bit grayscale), then 
i.histogram() returns an object of length 256. I was hoping to use the 
histogram method to do quick normalization of 12-bit grayscale images 
captured from a video camera.

Example:

 >>> from PIL import Image
 >>> img = Image.new('I', (255,255), (1 << 11) - 1)
 >>> img.getpixel((0,0))
2047
 >>> h = img.histogram()
 >>> len(h)
256
 >>> for i in range(len(h)):
... 	if h[i] > 0:
... 		print i, h[i]
... 		
 >>>

In other words, the histogram is all zeroes. Is this a bug in the histogram 
routine or is it the intended behavior? I see this behavior with both PIL 
1.1 and PIL 1.1.1, with Python 2.0 under Win98 and WinNT. The PIL manual 
does not explain what to expect here.

Thanks for any guidance,
Jonathan
===========================================================================
Jonathan M. Gilligan                     <jonathan.gilligan@vanderbilt.edu>