Hacker News new | ask | show | jobs
by GuB-42 9 days ago
As an argument for 255, take the extreme case of a black and white image, single bit, 0 is black and 1 is white.

It seems pretty obvious that you want 0 to map to 0.0 and 1 to 1.0. It is black and white, not light gray (0.25) and dark gray (0.75). It means that you normalize a black and white image by 1, not 2.

For 2 bits, you would normally have 0 = black, 1 = light grey, 2 = dark grey, 3 = black. So it is natural to map it to 0.0, 0.33, 0.66, 1.0, again, you want your black to be black and your white to be white, you also want equal spacing, so normalize by 3.

Follow the logic to 8 bits and you will normalize by 255, because you want black to be 0.0 and white to be 1.0, even though the difference starts to get really small with 8 bits.

Another way to see things is that with the alterative normalization (256 for 8 bits), the output range depends on the number of bits: [0.25, 0.75] for 1 bit, [0.125, 0.875] for 2 bits, etc... You typically don't want that, more bits should mean more nuances, but the contrast should stay the same.

1 comments

I appreciate that the author concluded you should use 255, because this approach here (making sure the minimum and maximum of the range actually map to 0 and 1) makes so much sense I never considered you could or ever would want to do it any other way.