Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #3958

im.histogram() groups pixel counts into 256 bins per channel, even for I and F mode images (which have pixel values of 0 to 65535, meaning that you could have 65536 bins in theory).

from PIL import Image
for mode in ("1", "L", "I", "F"):
    im = Image.new(mode, (1, 1))
    assert len(im.histogram()) == 256

The ImageStat module performs operations on that histogram. This means that for I and F mode images, ImageStat can only report what it has been given.

from PIL import Image, ImageStat
im = Image.new("I", (100, 1))
px = im.load()
for i in range(99):
    px[i, 0] = 65535 - i
stat = ImageStat.Stat(im)
print(stat.mean[0])  # 251.47

So I've added a note that mean, median,rms and the maximum extrema can't be more than 255.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageStat module incompatibility with color channels having range > 256

2 participants