[Image-SIG] PIL histogram bin 255 empty
fredrik at pythonware.com
Tue Sep 25 09:39:33 CEST 2007
Christopher Jones wrote:
> With mode I images, the histogram method sometimes returns bin 255
> empty, counting the getextrema maximum value in bin 254 instead. Is this
> a bug or is bin 255 treated in a special way, perhaps to count clipped
what is the getextrema() when this happens?
my guess is that it's a rounding error in the histogram code; it
scale = 255.0F / (max - min);
for each pixel:
i = (int) ((pixel-min)*scale);
if (i >= 0 && i < 256)
I don't have time to verify this right now, but I guess changing the
index calculation to:
i = (int) ((pixel-imin)*scale + 0.5);
would take care of this.
(the whole histogram-of-I/F approach feels a bit odd; not sure why it
was done that way, really).
More information about the Image-SIG