Live data from Hacker News

Should you normalize RGB values by 255 or 256?

30fps.net

51–60 of 156 posts

Re: Should you normalize RGB values by 255 or 256?

#52

The author is confusing bins with bin edges. In their first plot, the standard approach looks strange because 0-7 should be the bin edges, not the center points as shown in the plot. You can see this confusion again in the histogram example. There are only 255 bins, not 256. If you fix that mistake and remove the 0.5 offset, then the histogram is distributed correctly at both ends.

2*8 = 256. You can represent 256 distinct values, bins, with an 8 bit number. If you stick a 0 in that first one, it takes a bin. If you fill the rest with by-one increasing integers, then the max value will be 255, thus the 2*bits - 1, which is the max value you can store.

Re: Should you normalize RGB values by 255 or 256?

#53
post #4

I'll argue for the +0.5 solution. First, I don't like half-sized intervals at the edges, and second, a 255-based representation is typically a SDR (not HDR) image. RGB values represent luminances against some adapted state, and a "zero" in a daylit scene is not "zero luminance" - it's just about 0.001x as bright as the brightest point - it's millions of photons, way more than zero. In a sense our eyes experience cont…

> In a sense our eyes experience contrast on a sliding scale There's a whole visual center to check the amount of incoming light and adjust your pupils for you. It's intentionally reactive. > and there is no absolute zero in the system. There maybe is. I think we call that "blind." > broadcast systems historically used 16-235 as their luminance range for SDR Mostly because it was a fully analog system and these all t…

>> and there is no absolute zero in the system.

> There maybe is. I think we call that "blind."

If you go looking into that, you'll see that the reality is far far more complex [0]

"The number of people with no light perception is unknown, but it is estimated to be less than 10 percent of totally blind individuals."

[0] https://chicagolighthouse.org/sandys-view/what-blind-people-...

Re: Should you normalize RGB values by 255 or 256?

#54
post #4

I'll argue for the +0.5 solution. First, I don't like half-sized intervals at the edges, and second, a 255-based representation is typically a SDR (not HDR) image. RGB values represent luminances against some adapted state, and a "zero" in a daylit scene is not "zero luminance" - it's just about 0.001x as bright as the brightest point - it's millions of photons, way more than zero. In a sense our eyes experience cont…

> broadcast systems historically used 16-235

For 8-bit, 16 maps to 7.5IRE which is the well understood legal black. Mapping 235 means they mapped peak to 110IRE. This is based on a 0-120IRE scale. This gets weird as the broadcast limit for video was 100IRE allowing for the chroma to reach 110IRE. So if you're trying to limit your white values to 235, that'll be higher than is broadcast safe. Of course, nobody cares about NTSC broadcast limits any more. However, to this day, I still see out of spec tapes marked as "broadcast master" that have been ingested for streaming use. It drives me crazy to this day, and it's only getting worse as people don't even have scopes to adjust the VTR's TBC properly.

Re: Should you normalize RGB values by 255 or 256?

#55
post #3

If you have a ruler and it goes to 12 inches, you should normalize by the length L and not by 13, the number of points on the ruler.

But who says that the numbers are representing the points, rather than representing the intervals between the points?

Re: Should you normalize RGB values by 255 or 256?

#56

Earlier quoted context omitted.

FP Division by constant is optimized by a compiler into a multiply. Graphics processing typically happens on the GPU these days, and on all recent GPUs FPMUL belongs to the class of lowest-latency operations. That is, there are no other instructions that complete faster.

That's only valid to do if the reciprocal is representable exactly.

That's not totally true. It's sufficient to be exactly representable, but you only need the reciprocal rounding error to be small enough to guarantee the multiplication rounding step fixes it across the entire range of numerators. For IEEE754 f16 values, there are 28 such extra values, the positive and negative sides of 1705/x where x is a power of 2 at least as great as 2048.

Re: Should you normalize RGB values by 255 or 256?

#57
post #3

If you have a ruler and it goes to 12 inches, you should normalize by the length L and not by 13, the number of points on the ruler.

I’m dumb. Doesn’t 0 start at the beginning?

It's right up there with the confusion if 2000 was the new year of the 21st century or the last year of the 19th century.

Re: Should you normalize RGB values by 255 or 256?

#58
post #50

The author is confusing bins with bin edges. In their first plot, the standard approach looks strange because 0-7 should be the bin edges, not the center points as shown in the plot. You can see this confusion again in the histogram example. There are only 255 bins, not 256. If you fix that mistake and remove the 0.5 offset, then the histogram is distributed correctly at both ends.

How do you fit 256 distinct values into 255 bins?

By counting the edges

Re: Should you normalize RGB values by 255 or 256?

#59
post #18
post #4

I'll argue for the +0.5 solution. First, I don't like half-sized intervals at the edges, and second, a 255-based representation is typically a SDR (not HDR) image. RGB values represent luminances against some adapted state, and a "zero" in a daylit scene is not "zero luminance" - it's just about 0.001x as bright as the brightest point - it's millions of photons, way more than zero. In a sense our eyes experience cont…

I agree. Additionally, both 0.0 and 1.0 don't really exist for dithered signals, so a byte should map to [0.5, 255.5] before division by 256. This also solves the signed integer asymmetry, as a signed byte maps to [-127.5, 127.5] before division by 128. I wonder if audio DSP folks have done this already.

Thinking about this more, dithering requires negative values to cancel out when adding. Works for audio, but color doesn't have negative numbers.

Re: Should you normalize RGB values by 255 or 256?

#60

The author is confusing bins with bin edges. In their first plot, the standard approach looks strange because 0-7 should be the bin edges, not the center points as shown in the plot. You can see this confusion again in the histogram example. There are only 255 bins, not 256. If you fix that mistake and remove the 0.5 offset, then the histogram is distributed correctly at both ends.

No, the author understands the problem way deeper than you do.

You haven't grasped the fact that the choice isn't obvious, and has subtle trade-offs.

If you don't believe the author, check the other posts he references.

Post reply on HN