Wednesday, January 12, 2011

Bit Depth and Confusion


As some may know, the last post went postal.

A total count of around 37,000 views and climbing on a subject that was aimed at about 250 daily readers.

In the furor that arose, there has been a colossal depth and diversity of discussions. Some utterly positive, productive, and explanatory, and some utterly off topic, tangential, and otherwise.

There is likely much to discuss from the output.

This post focuses on one specific aspect of the last post, that, as a result of the information and insight from some of the powerful minds over at LWN, helps to clarify the grossly misunderstood area of bit depth[1].

I can only hope this doesn't erupt into a flame war. These are real world examples with real world data and now, thankfully, some real world developers speaking up and offering further insight. That interaction is a core strength of Libre software.

If there is a weakness out there, it is the result of voting up commentary that ranges from inaccurate to completely incorrect. This is not an attempt to vilify those postings, but rather shed some light onto the issue in a practical way. It is hoped that the examples found at LWN and Hacker News provide compelling evidence of the importance of bit depth to even the most casual reader.

This discussion strictly pertains to the manipulations performed on images. In particular, it seeks to dismantle the notion that high bit depth calculations are only relevant on high bit depth imaging devices. This is simply and fundamentally untrue.

This post builds upon and heavily relies on the strength of minds over at LWN, Hacker News, and some very bright developers in the Libre community. It is hoped that further input can help to flesh this issue into a far more comprehensible subject than it currently is.

Q: What is Bit Depth?

Bit depth is the amount of information used to store a color value in a color system[2]. In an RGB additive light system such as what you are likely looking at now, each component of red, green, and blue is modeled into numbers.

A common format is eight bits per channel. This yields a scale of 0-255 for each red, green, and blue component in a typical image.

Perhaps the most prevalent system is a 24 bit per pixel representation. This is simply three channels of eight bits each of color accuracy[3].

Q: My Monitor is only Eight Bits Per Channel? Why Do I Care?

The monitor is an end point. It is an output device.

As soon as we begin to discuss the area of manipulation of images, we engage the issue of bit depth. In particular, we are speaking of bit depth accuracy. While the pipeline looks consistent at eight bits per channel from a starting eight bit JPG image to an eight bit per channel display device, we must also remember that the result of any and all manipulations are also constrained to the eight bit scale.

This results in intermediate values being rounded to fit within that scale. Many of these will end up being visible on an eight bit per channel monitor.

Q: These are microscopic theoretical differences aren't they? Why do I care?

You might not.

There is a good chance though, if you are an audience using an image manipulation program, you have at least a passing interest in output image quality. And if you do indeed care, bit depth calculation accuracy comes into the mix and brings with it visible output implications.

Remember that consecutive image manipulations are commonplace in an imaging editing system. Within a limited bit depth scale, those consecutive operations compound and conspire against each other and compound. Repeated rounding accuracy is cumulative in many instances.

The result is an output image that can be seriously degraded.

Q: There are some people that say this is all a myth and some that say it isn't, though. Is this real?

At risk of being inflammatory, anyone that suggests that the issue of bit depth only applies to deep outputs formats such as printing or deep professional grade sources, is unequivocally wrong.

For this however, we should turn to some demonstrations.

The first case study would be from the MyPaint application. MyPaint is a digital painting application. A good deal of design focus goes into focusing on digital painting and display output. The curator of MyPaint is Martin Reynolds and his exemplary mind has taken these sorts of mythical concepts to task in code.

Note that this is a scenario where many would suggest bit depth does not matter as we are trapped within the eight bit digital output of a typical display.


It should be clear from this image alone that in fact, there is a striking visible difference between eight bits and fifteen bits per channel representations. Even though the output source is identical in both scenarios, the internal math gives entirely different results.

From Martin Reynolds's example here deeper bit depth during computation has a visible and distinct impact on image quality.

The full article can be found at the MyPaint site. Full credit goes to Boudewijn Rempt at LWN for this citation and discussion. Boudewijn Rempt is a remarkable mind also contributing to the Krita project, so his opinions and expertise are backed up with a good deal of practical reference.

Q: Are there examples of differing bit depth sources that highlight the issue?

Yes.

A higher bit per channel input image holds more steps of data than a reduced eight bit channel image. This yields more granularity within the information.

A single image manipulation is provided in the following example. Notice how there is quite radical posterization, or color banding, in the image after only a single manipulation.


This sample is a crop from an existing article. The full article (author unknown) can be found PhotoshopEssentials. Full credit goes to julian37 at Hacker News for discussing and providing this example.

Q: So, limited eight bit working space influences all image manipulations even if the output is only destined for eight bit or less displays?

Yes.

In summary, strictly eight bit images operated on in an eight bit workspace will yield rounding errors that result in degraded image quality.

A simple way of expressing this is to consider a value of 127 red. It is fundamentally impossible to divide such a value in half without throwing out a degree of information. When we throw out that data, we are degrading the image in visibly noticeable ways. Greater bit depth work spaces provide significantly more accuracy and hence reduces the visual impact of this issue.

The limited range of 256 total steps per channel is obviously important. How important? What is the threshold for error?

"The magnitude of these errors is surprising. The brightest spots in the difference image correspond to a difference of only 2 pixel values!" -- Andrew Mihal experimenting with code on Enblend.

Martin Reynold's MyPaint example above beautifully illustrates this.

The issue becomes even more noticeable when we compare it against an image of deeper bit depth as in the second example.

Whether you are doing photographic or pure shape based imaging, the moment that we enter into a limited bit depth space such as eight bits per channel, we are discarding data accuracy when manipulating. Blurs, colour manipulations, compositing, and even simple anti-aliasing is impacted.

There is no magic here. There is no hypothesis or hyperbole. In the end, this is simple and fundamental math and rounding.

There is no question that this is a critically misunderstood issue surrounded in confusion and misinformation.

Whether this difference is noticeable and meaningful to the reader is a personal and subjective thought that shall remain open. For those more heavily involved with image manipulations and output thereof, this is a well documented and core issue.

Thank you all for reading...

Further reading:

The LWN thread regarding the implications of eight bit rounding.
The Hacker News thread regarding bit depth.
Andrew Mihal talks about precision and rounding errors.


If there are any inaccuracies or articles of further relevance, please comment and all efforts will be made to integrate them where appropriate.

[1] That includes anything to do with GEGL and what it brings to GIMP etc.
[2] This avoids the complications of color space transformations and like areas. It would likely only serve to confuse the issue without bringing much additional value to the discussion.
[3] It should also be noted that despite a huge number of graphics cards offering 32 bit in their titles, they offer only eight bits per RGB channel with an additional eight bit transparency layer. It is current convention that true ten bit per channel video cards are presented as 30 bit cards to avoid this confusing piece of historical legacy.

5 comments:

Jason Simanek said...

You've certainly helped explain bit-depth. Thanks. I understand the basic math, but it never hurts to review.

The examples shown above clearly show the benefits of higher bit-depths, but the examples are all addressing images for the screen. What about high resolution images intended for print? Do the side effects of manipulating an image in low bit-depth (8 bit, for example) become less noticeable as image resolution increases?

Granted, there's still color data being lost due to repeated rounding-up (as you describe above) but surely having an increased number of pixels to work with would decrease the perceivable side effects?

Troy James Sobotka said...

"Do the side effects of manipulating an image in low bit-depth (8 bit, for example) become less noticeable as image resolution increases?"

There could be many variables here.

I'd think that the ratio of operation to overall density would be the driving factor. A 15 pixel adjustment on a 300DPI destination would probably be less noticeable. A proof would be the ultimate barometer.

My gut says that if you are subject to rounding errors, the ultimate quality of the image is suffering at various points and, at some point, those are going to end up in your print.

So unless the modifications are trivially small, then they are probably going to be visible if the print is of a sufficient quality. Of course, if the adjustments are that insignificant, it would seem illogical to be adjusting at all in the first place.

Thanks for dropping by.

Anonymous said...

Have you tried Krita? Would be interesting to know what you think why Krita is inadequate.

Krita has higher bit depth and linear light. No idea how performance compares, but it was improved in the latest version.

While Krita is for painting, it has image manipulation stuff. So could it be closer to your needs?

Anonymous said...

Have you tried Krita? Would be interesting to know what you think why Krita is inadequate.

Krita has higher bit depth and linear light. No idea how performance compares, but it was improved in the latest version.

While Krita is for painting, it has image manipulation stuff. So could it be closer to your needs?

Troy James Sobotka said...

"Do the side effects of manipulating an image in low bit-depth (8 bit, for example) become less noticeable as image resolution increases?"

There could be many variables here.

I'd think that the ratio of operation to overall density would be the driving factor. A 15 pixel adjustment on a 300DPI destination would probably be less noticeable. A proof would be the ultimate barometer.

My gut says that if you are subject to rounding errors, the ultimate quality of the image is suffering at various points and, at some point, those are going to end up in your print.

So unless the modifications are trivially small, then they are probably going to be visible if the print is of a sufficient quality. Of course, if the adjustments are that insignificant, it would seem illogical to be adjusting at all in the first place.

Thanks for dropping by.

Post a Comment