im.histogram() is 256 bins per band for RGB (768 numbers). Print a few bins.
Goal
Count how many pixels are pure black vs white on a tiny image.
from PIL import Image
im = Image.new('L', (10, 10), 0)
for i in range(10):
im.putpixel((i, 0), 255)
h = im.histogram()
print('bin0', h[0], 'bin255', h[255], 'len', len(h))from PIL import Image
im = Image.new('RGB', (4, 4), (0, 128, 64))
print(len(im.histogram()))from PIL import Image
h = Image.new('L', (8, 8), 128).histogram()
print(h[128])from PIL import Image
print(sum(Image.new('L', (5, 5), 0).histogram()))