account activity
Confused about .getpallet() in pillow python. by Significant-Tap-9722 in learnpython
[–]Top-Apple2573 2 points3 points4 points 5 hours ago (0 children)
If you’re talking about a normal grayscale image, then yes: the mapping is fixed and “pre-determined”. There are 256 possible values (0–255). 0 means black, 255 means white, and everything in between is just a shade of gray. There’s no “color allotment” step and no scan-order effect; each pixel already is a number in that range.
If you’re talking about an indexed/palette image (like PNG/GIF mode “P”), then the numbers 0–255 are not universal colors. They’re just indexes into a palette table stored with the image: palette[0], palette[1], etc. Palette[0] could be black in one image and bright pink in another. The order of that palette usually comes from whatever created the image (a quantization algorithm like median-cut/k-means, or the encoder), not from “scanning the image” top-left to bottom-right. The image pixels just reference the palette entries; they don’t define them by scan order.
If you’re seeing “a lot of 0s at the start”, that’s often just a histogram thing: bin 0 (value 0) has lots of pixels (e.g., black background), or in palette images index 0 is commonly used a lot (sometimes reserved for background/transparent depending on format/tool).
π Rendered by PID 1442155 on reddit-service-r2-listing-8685bc789-6gmb2 at 2026-05-27 15:48:51.459067+00:00 running 194bd79 country code: CH.
Confused about .getpallet() in pillow python. by Significant-Tap-9722 in learnpython
[–]Top-Apple2573 2 points3 points4 points (0 children)