Bit Depth: Difference between revisions

From RawPedia
Jump to navigation Jump to search
m (DrSlony moved page 8-bit and 16-bit to Bit Depth: Previous title made obsolete by support for more bit depths)
 
(Rewrote article)
Line 1: Line 1:
"8-bit" when referring to image formats typically means that the program assigns 8 [https://en.wikipedia.org/wiki/Bit bits] (eight "1" or "0" values, which together make one [https://en.wikipedia.org/wiki/Byte byte], capable of representing an [https://en.wikipedia.org/wiki/Integer integer] value from 0 [00000000] to 255 [11111111]) to each pixel's color channel, and each pixel in the files RawTherapee saves has three color channels - red, green and blue.
== Introduction ==


Most modern raw-capable [https://en.wikipedia.org/wiki/DSLR DSLR] cameras use 12- or 14-bit analog-to-digital converters to record the sensor data. This means that when choosing an 8-bit-per-channel output format in your camera, such as JPEG, one loses some information. It's not as simple as it may seem though, cameras record data linearly (due to limitations in hardware design) while JPEG, TIFF and PNG [https://en.wikipedia.org/wiki/Gamma_correction gamma encode] their data meaning that they distribute more values in the shadow range and less in the highlights which better matches the eye's sensititvity. This means that an 8 bit JPEG can display as much as log2((1/2^8)^2.2) = 17.6 stops of dynamic range which indeed exceeds the 14 stops of the current best cameras, which explains why you sometimes can see a camera's shadow noise even in an 8 bit JPEG. However due to the fewer values in highlights we lose precision there compared to the camera. Practically this is not a problem when the output file is the definitive one and will not be processed anymore, however a photo can be vastly improved when saved as raw data and processed using a state of the art raw processing program, such as your's truly - RawTherapee.
You will hear terms such as "8-bit", "16-bit", "24-bit", "32-bit", "64-bit" and "96-bit" with reference to digital images. This article will clarify what those things mean.


Once you have processed a photo in RawTherapee, you are faced with the same choice - to save the image with a color resolution of 8 bits per channel, or 16 bits per channel (only [https://en.wikipedia.org/wiki/TIFF TIFF] and [https://en.wikipedia.org/wiki/Portable_Network_Graphics PNG], not [https://en.wikipedia.org/wiki/JPEG JPEG]). If you plan to post-process your photos after RawTherapee in a 16-bit-capable image editing program, it is better to save them in a lossless 16-bit format. Uncompressed TIFF is suggested as an intermediate format, as it is quick to save and stores all the metadata ([https://en.wikipedia.org/wiki/Exif Exif], [https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model IPTC], [https://en.wikipedia.org/wiki/Extensible_Metadata_Platform XMP]) of the original file (PNG generally discards metadata!).
Digital images consist of millions of pixels, and each pixel describes one or more color channels. Grayscale images need only one channel (a value of 0 could represent pure black, 255 could represent pure white, and the values in-between would then represent shades between black and white), while RGB color images need three channels - one describes red, one green and one blue. Each channel describes only an intensity, so there is nothing inherently green about a number which describes a pixel from the green channel; colors derive from the interaction between all three channels in the [https://en.wikipedia.org/wiki/RGB_color_model RGB color model].


There is some confusion over the naming of 8, 16, 24 and 32-bit files. Here is a clarification, but it gets confusing, so put your tin foil hat on. You do not actually need to read this to use RawTherapee, it is just background knowledge.
A single pixel could represent more than three channels, for example it could contain information about an alpha channel (which describes transparency) or an infra-red channel (which some scanners support).
Each of the red, green and blue channels stored in a JPEG, PNG or TIFF file is actually a colorless image, but when you combine these three colorless images together, you get a color image. This is how all digital representation of images works - color images are always decomposed into their components in one way or another. Of the file formats that RawTherapee can save to (JPG, PNG and TIFF), each pixel contains information for three color channels - red, green and blue. We say "8 bits per channel" to make it clear that these 8 bits apply to one color channel only. The reason is that you might encounter references to "8-bit images", and here it gets confusing, because the person who wrote that may have been referring to a grayscale format which stores only one channel, or to a color format that stores three channels, with 8-bit precision each. Another notation for the very same "8-bit" images that RawTherapee saves is "24-bit". Woo, confusing. Or is it? Each pixel is made of 3 channels, and each channel stores 8 bits of data, so we have a total of 24 bits of data per pixel. It gets worse. Image editing programs can also store a fourth channel, called "alpha". To put it simply, alpha describes how transparent a pixel is. These alpha channels also have a "color resolution" of 8 bits. Both PNG and TIFF files can handle alpha, JPEG can't. If you have an 8 bits per channel image with an alpha channel, it can also be described as a 32-bit image; R (8) + G (8) + B (8) + alpha (8) = 32. The ultimate problem is that you can also have an image that assigns as many as 32 bits per color channel. These images can be described as "32-bit" images as well as "96-bit images" (because R (32) + G (32) + B (32) = 96). All real HDR files are stored in image formats that assign at least 16-bit floating-point numbers for each pixel per color channel, such as the EXR format, or 32-bit ones, such as the RGBE format.
 
To summarize, an "8-bit per channel" image with three channels (RGB) can also be called a "24-bit per pixel" image, and a "16-bit per channel" image with three channels can also be called a "48-bit per pixel" image. In both cases use the former (the full "x bit per channel" description, don't just say "x bit"!), it’s more clear what you mean.
The higher the bit depth, the more precisely a color can be described, at a cost of requiring longer computation, more RAM and more storage space.
 
== Bits Per What? ==
 
Bit depth is expressed as a value which describes either the number of '''bits per pixel''' (BPP), or '''bits per channel''' (BPC). The very popular [https://en.wikipedia.org/wiki/JPEG JPEG format] typically saves images with a precision of 8 bits per channel, using three channels, for a total of 24 bits per pixel. The [https://en.wikipedia.org/wiki/TIFF TIFF format] supports various bit depths, for example 32 bits per channel for a total of 96 bits per pixel.
 
When describing bit depth, state what you're describing to leave no room for ambiguity. For example, if someone says they have a "32-bit" image, does that mean the image has 32 bits per channel, or does it have 4 channels at 8 bits per channel?
 
== Precision ==
 
What difference does bit depth make? The more bits are available to describe a color, the more precisely you can describe that color.
 
<ul>
  <li>A precision of 1 bit per channel means that there is only 1 bit to describe the value. A bit can only be 0 or 1, so you can only represent two values, which typically would mean black or white.</li>
  <li>A precision of 2 bits per channel means there are two bits available to describe a color. Since each bit can be 0 or 1, and there are two of them, they can represent 4 possible values:
    <pre>[00] = 0
[01] = 1
[10] = 2
[11] = 3</pre>
If we use 0 to represent black and 3 to represent white, there are two additional shades of gray which can be described.
  </li>
  <li>A precision of 8 bits per channel means there are 8 bits which can represent 255 values:
    <pre>[0000 0000] = 0
[0000 0001] = 1
(...)
[1111 1110] = 254
[1111 1111] = 255</pre>
If we use 0 to represent black and 255 to represent white, 254 shades of gray can also be described. This is what JPEG files use - 8 bits per channel, with 3 channels. It is sufficient to be used for most ready-to-view photographs in the [https://en.wikipedia.org/wiki/sRGB sRGB color space] without visible posterization, so you can use it when saving photographs ready to be viewed over the internet.
It is not suitable as an intermediate format nor as a final format if there is a chance you might need to tweak the photograph later on, as you run the risk of introducing posterization artifacts, depending on the strength of adjustments. 8-bit precision is not enough to represent a high dynamic range scene in a linear way without posterization, i.e. you theoretically could use 8 bits of precision to describe a high dynamic range scene linearly, but the numbers would be so far apart that heavy posterization would occur. For instance, if a photograph captures a sunny day in the park, and if we assume that black should be 0 and white should be 1 000 000, we could map 0 to 0 and 255 to 1 000 000, but then there would only be 254 values left for describing all the remaining 999 999 shades of the original scene.
  </li>
  <li>A precision of 16 bits per channel (16-bit integer) means there are 16 bits which can represent 65536 values:
    <pre>[0000 0000 0000 0000] = 0
[0000 0000 0000 0001] = 1
(...)
[1111 1111 1111 1110] = 65534
[1111 1111 1111 1111] = 65535</pre>
Digital cameras typically capture light in 12-bit or 14-bit precision (and due to noise and imprecise electronics the lowest bits are of dubious quality). 16 bits per channel are enough for most photography needs, including for use in intermediate files (if you want to pass an image from one program to another without data loss).
  </li>
  <li>A 16-bit [https://en.wikipedia.org/wiki/Floating-point_arithmetic floating point] image, also known as [https://en.wikipedia.org/wiki/Half-precision_floating-point_format half-precision floating point], can represent a wider range of values than 16-bit integer. The precision is not constant and some values are rounded off.
  </li>
  <li>A 32-bit [https://en.wikipedia.org/wiki/Floating-point_arithmetic floating point] image can represent 4.3 billion values per channel, and requires roughly twice the disk space as a 16-bit image. Few programs support 32-bit images.
  </li>
</ul>
 
== Gamma Encoding ==
 
[https://en.wikipedia.org/wiki/Gamma_correction Gamma encoding] can be used when saving image files, meaning that values are distributed in such a way that more can be allocated in the shadow range than in the highlight range, which better matches the human eye's sensitivity. This means that an 8 bit JPEG can display as much as log2((1/2^8)^2.2) = 17.6 stops of dynamic range, which indeed exceeds the 14 stops of the current best cameras, which explains why you sometimes can see a camera's shadow noise even in an 8-bit JPEG. However, due to the non-linear distribution, we lose precision compared to the raw file recorded in a linear way by the digital camera. Practically this is not a problem when the output file is the definitive one and will not be processed anymore, however a photo can be vastly improved when saved as raw data and processed using a state of the art raw processing program, such as yours truly - RawTherapee.
 
== After RawTherapee ==
 
Once you have adjusted a photo in RawTherapee and are ready to [[Saving_Images|save]], you are faced with a choice of [[Color_Management#Output_Profile|output format, bit depth]], [[Color_Management_addon#Output_space_.22Output_Profile.22|color space and gamma encoding]]. If you plan to post-process your photos after RawTherapee in a 16-bit-capable image editing program, it is better to save them in a lossless 16-bit format. Uncompressed 16-bit TIFF is suggested as an intermediate format as it is the fastest to save. 32-bit files are roughly twice the size and not well supported by other programs.

Revision as of 23:32, 5 January 2019

Introduction

You will hear terms such as "8-bit", "16-bit", "24-bit", "32-bit", "64-bit" and "96-bit" with reference to digital images. This article will clarify what those things mean.

Digital images consist of millions of pixels, and each pixel describes one or more color channels. Grayscale images need only one channel (a value of 0 could represent pure black, 255 could represent pure white, and the values in-between would then represent shades between black and white), while RGB color images need three channels - one describes red, one green and one blue. Each channel describes only an intensity, so there is nothing inherently green about a number which describes a pixel from the green channel; colors derive from the interaction between all three channels in the RGB color model.

A single pixel could represent more than three channels, for example it could contain information about an alpha channel (which describes transparency) or an infra-red channel (which some scanners support).

The higher the bit depth, the more precisely a color can be described, at a cost of requiring longer computation, more RAM and more storage space.

Bits Per What?

Bit depth is expressed as a value which describes either the number of bits per pixel (BPP), or bits per channel (BPC). The very popular JPEG format typically saves images with a precision of 8 bits per channel, using three channels, for a total of 24 bits per pixel. The TIFF format supports various bit depths, for example 32 bits per channel for a total of 96 bits per pixel.

When describing bit depth, state what you're describing to leave no room for ambiguity. For example, if someone says they have a "32-bit" image, does that mean the image has 32 bits per channel, or does it have 4 channels at 8 bits per channel?

Precision

What difference does bit depth make? The more bits are available to describe a color, the more precisely you can describe that color.

  • A precision of 1 bit per channel means that there is only 1 bit to describe the value. A bit can only be 0 or 1, so you can only represent two values, which typically would mean black or white.
  • A precision of 2 bits per channel means there are two bits available to describe a color. Since each bit can be 0 or 1, and there are two of them, they can represent 4 possible values:
    [00] = 0
    [01] = 1
    [10] = 2
    [11] = 3

    If we use 0 to represent black and 3 to represent white, there are two additional shades of gray which can be described.

  • A precision of 8 bits per channel means there are 8 bits which can represent 255 values:
    [0000 0000] = 0
    [0000 0001] = 1
    (...)
    [1111 1110] = 254
    [1111 1111] = 255

    If we use 0 to represent black and 255 to represent white, 254 shades of gray can also be described. This is what JPEG files use - 8 bits per channel, with 3 channels. It is sufficient to be used for most ready-to-view photographs in the sRGB color space without visible posterization, so you can use it when saving photographs ready to be viewed over the internet. It is not suitable as an intermediate format nor as a final format if there is a chance you might need to tweak the photograph later on, as you run the risk of introducing posterization artifacts, depending on the strength of adjustments. 8-bit precision is not enough to represent a high dynamic range scene in a linear way without posterization, i.e. you theoretically could use 8 bits of precision to describe a high dynamic range scene linearly, but the numbers would be so far apart that heavy posterization would occur. For instance, if a photograph captures a sunny day in the park, and if we assume that black should be 0 and white should be 1 000 000, we could map 0 to 0 and 255 to 1 000 000, but then there would only be 254 values left for describing all the remaining 999 999 shades of the original scene.

  • A precision of 16 bits per channel (16-bit integer) means there are 16 bits which can represent 65536 values:
    [0000 0000 0000 0000] = 0
    [0000 0000 0000 0001] = 1
    (...)
    [1111 1111 1111 1110] = 65534
    [1111 1111 1111 1111] = 65535

    Digital cameras typically capture light in 12-bit or 14-bit precision (and due to noise and imprecise electronics the lowest bits are of dubious quality). 16 bits per channel are enough for most photography needs, including for use in intermediate files (if you want to pass an image from one program to another without data loss).

  • A 16-bit floating point image, also known as half-precision floating point, can represent a wider range of values than 16-bit integer. The precision is not constant and some values are rounded off.
  • A 32-bit floating point image can represent 4.3 billion values per channel, and requires roughly twice the disk space as a 16-bit image. Few programs support 32-bit images.

Gamma Encoding

Gamma encoding can be used when saving image files, meaning that values are distributed in such a way that more can be allocated in the shadow range than in the highlight range, which better matches the human eye's sensitivity. This means that an 8 bit JPEG can display as much as log2((1/2^8)^2.2) = 17.6 stops of dynamic range, which indeed exceeds the 14 stops of the current best cameras, which explains why you sometimes can see a camera's shadow noise even in an 8-bit JPEG. However, due to the non-linear distribution, we lose precision compared to the raw file recorded in a linear way by the digital camera. Practically this is not a problem when the output file is the definitive one and will not be processed anymore, however a photo can be vastly improved when saved as raw data and processed using a state of the art raw processing program, such as yours truly - RawTherapee.

After RawTherapee

Once you have adjusted a photo in RawTherapee and are ready to save, you are faced with a choice of output format, bit depth, color space and gamma encoding. If you plan to post-process your photos after RawTherapee in a 16-bit-capable image editing program, it is better to save them in a lossless 16-bit format. Uncompressed 16-bit TIFF is suggested as an intermediate format as it is the fastest to save. 32-bit files are roughly twice the size and not well supported by other programs.