10
\$\begingroup\$

I know that a 24 bit image dedicates 8 bit each for R, G and B. Is it just for RGB color space. In YCbCr color space for a 24 bit JPEG image, how are the bits distributed?

\$\endgroup\$

4 Answers 4

3
\$\begingroup\$

There are a few formats for YCbCr. generally speaking the eye is more sensitive to changes in luminance (Y, brightness) than to changes in chroma (Cb, Cr, color). Thus, it is possible to erase some chroma information while retaining image quality.

Thus, the most "expensive" format is 4:4:4, where for each luma (Y) component there are 1 Red difference (Cr) and one Blue difference (Cb) components.

Then, applying the principle I mentioned, there is 4:2:2 where for each 2 Y components there are 1 Cb and 1 Cr. And it goes even further to 4:1:1 and 4:2:0, etc. More info here.

\$\endgroup\$
6
  • \$\begingroup\$ These patterns seem to refer to frequency sampling for video, not JPEG encoding. \$\endgroup\$
    – whuber
    Feb 5, 2011 at 21:42
  • \$\begingroup\$ @whuber: They're frequently used in discussing video coding, but JPEG also supports luminance with double the resolution of chrominance. In the case of JPEG, it's optional though -- chroma can be either full-res or half-res. \$\endgroup\$ Feb 5, 2011 at 22:15
  • 1
    \$\begingroup\$ The GIMP will use chroma subsampling by default when saving a JPEG, though it's easy to override. Can't remember if this applies to Photoshop too. \$\endgroup\$ Feb 7, 2011 at 13:20
  • 1
    \$\begingroup\$ The numbers, by the way, refer to the number of samples per 4 horizontal pixels for Y, Pr, and Pb. So 4:4:4 means all three channels sample every pixel; 4:2:2 means the Pr and Pb channels only sample every second pixel horizontally; 4:1:1 (I don't think this is ever used in photography, only in video) means Pr and Pb only sample every fourth pixel horizontally. 4:2:0 is a special deviation from this rule. It does NOT mean there is no Pb channel. What it means is that the Pr and Pb channels are halved in both horizontal and vertical direction, not just horizontal. \$\endgroup\$ Nov 15, 2012 at 23:59
  • 1
    \$\begingroup\$ I've been referring to Y Pb Pr when in digital form it's usually called Y Cb Cr. \$\endgroup\$ Nov 16, 2012 at 0:23
24
\$\begingroup\$

A JPEG may start out with 8 bits per R, G and B channel, but when stored in the JPEG it is stored very differently, where there is no real "bit depth" but instead values are stored as frequency coefficients of a given precision.

In JPEG what's more relevant is the quantization rate, which affects how much information is thrown away during the quantization stage of compression and thus how precise each coefficient is. This quantization rate is set by the "quality" setting when you save a JPEG in photoshop. It is not related to the bit depth as in a raster image though, and you could even say that a JPEG image doesn't have a bit depth while in JPEG format, although JPEG encoders/decoders start with/end with a 24-bit raster image.

The other major factor relevant in saving a JPEG is the chroma sub-sampling type. In a JPEG, you have the option of halving the horizontal, or both the horizontal and vertical, resolution of the color (Pr and Pb) channels relative to the luminance (lightness) channel. When decompressing, the color channels are interpolated and in most photographic subject matter it doesn't make a huge amount of difference.

Here's a rough summary of how an image gets turned into a JPEG.

  1. RGB values are converted to Y, Pb, Pr values. The YPbPr color space is better suited for efficient compression because it keeps the luminance information, which carries the most detail, in only one channel. This conversion is a simple arithmetic operation which is perfectly reversible, apart from if there is any rounding error.

  2. If using any chroma-subsampling (in other words, using anything other than 4:4:4 mode), then the vertical and/or horizontal resolution of the Pb and Pr channels only are halved. Thus these channels will have different pixel dimensions to the luminance channel. This leads to permanent loss of resolution in the color channels.

  3. For each channel, the image is divided up into blocks of 8 pixels by 8 pixels, which gives 64 linear values for each such block in each channel. If a channel is not a multiple of 8 pixels in either dimension, then the edge pixels are repeated (and will be thrown out when decompressing - thus JPEG compression is always more efficient with dimensions that are multiples of 8 pixels, or 16 if you factor in chroma subsampling).

  4. The 64 values in each block undergo a transformation from the space domain into the frequency domain, in this case called a discrete cosine transformation. You end up with 64 coefficients, each representing the amplitude of a particular frequency map over the area taken by that block. The first value is the lowest frequency which is effectively the average value of all the pixels, right up until the last values which describe the highest frequency component of the block. The earlier values all deviate a lot more, and are more important to the look of the final image than the later values in a block. This operation is perfectly reversible as long as you use enough precision.

  5. Then there is the quantization step, where each of the 64 coefficients you got to in the previous step is divided by some number (called the quantization factor), and the remainder is thrown out. This is where the precision of the samples are affected the most, but it's where you get the huge space savings from JPEG compared to lossless compression. Since everything is in the frequency domain since the previous transformation, this loss of accuracy does its best job at preserving perceptual image quality than simply reducing bit depth/accuracy of pixels would before this transformation. The reverse of this procedure is simply to multiply by the same number you divided the coefficients by, but of course since you threw the remainders away you end up with less precision of the coefficients. This results in permanent loss of quality, but not on a pixel-by-pixel basis but affecting the 8x8 block as a whole according to the frequency pattern of those coefficients.

  6. After this quantization it's typical for many of the later, less significant coefficients to be zero, so these are thrown out. Then a (lossless) variable-length coding routine encodes all the remaining coefficients in an efficient way, even though each one may use a different number of bits.

It's impossible to say that a certain quantization factor is equivalent to a certain bit depth since quantization does not give banding like when you reduce the bit depth, but instead gives an overall perceptual loss in detail, starting in the parts where you'd notice it less because it's of such low amplitude for its frequency.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ I think my brain just exploded. \$\endgroup\$ Feb 7, 2011 at 8:31
  • \$\begingroup\$ Chroma-subsampling doesn't just result in "loss of resolution". It introduces very noticeable artifacts especially in the red channel. \$\endgroup\$ Feb 8, 2011 at 4:43
  • \$\begingroup\$ @Mark Ransom those artifacts are nothing more than a result of halving the resolution in the color channels, and of the interpolation necessary to account for that after decompression. It shouldn't ever produce any "noticeable artifacts" other than that caused by blurring over of resolution, although there may exist some decoders which screw up this interpolation or do very simple nearest-neighbour interpolation, resulting in blockiness that is quite noticeable for red details on black (or magenta on blue, etc). This was a common problem on some early DVD players for example. \$\endgroup\$ Feb 8, 2011 at 5:20
  • 5
    \$\begingroup\$ I don't think I've ever seen a better, easier to understand explanation of jpeg - or really lossy - image compression. definite +1 \$\endgroup\$
    – jay.lee
    Feb 8, 2011 at 11:16
  • \$\begingroup\$ Sorry, I didn't mean to imply that the subsampling causes the artifacts. It's just that the existing errors from quantization get blown up 2X, making them much more visible. I think it's important to know that the visible effect of subsampling is more than just a little added fuzziness. \$\endgroup\$ Feb 11, 2011 at 3:08
1
\$\begingroup\$

Representing the chroma (Cb Cr) in separate channels from the luma (Y) has another positive effect on compression. Most of the visible information is in the luma channel. Human eyes tolerate both lower spatial resolution and more aggressive quantization in the chroma channels. So an aggressively compressed image can end up consuming about 10% of the file space for chroma, and the rest for luma, and still look decent.

At the end of the day it's still lossy compression.

\$\endgroup\$
-1
\$\begingroup\$

Approximately 8 bits for each channel, but there are several slightly different ways to do it. The details are given in the Wikipedia article on YCbCr.

\$\endgroup\$
3
  • \$\begingroup\$ This was stated in the question. Provide a more detailed answer. \$\endgroup\$ Feb 7, 2011 at 8:33
  • \$\begingroup\$ @Nick Where was "this" stated in the question, exactly? The question, as it stands now, says "In YCbCr color space for a 24 bit JPEG image, how are the bits distributed?" I have said how they are distributed, assuming--as anyone who understands the question would--that the channels are Y, Cb, and Cr. My answer is a correct summary of the Wikipedia article. SE policy is to provide summaries rather than copy material wholesale (although it's easy, I admit, to provide some borderline examples of long quotations elsewhere on this site). \$\endgroup\$
    – whuber
    Feb 7, 2011 at 13:25
  • \$\begingroup\$ I think this kind of answer, while not as great as a full explanation, is way better than one which just cuts and pastes from the Wikipedia, or even which paraphrases a whole Wikipedia article. If the Wikipedia is good, telling people about it is helpful. And if that's all your answer is contributing, being upfront and just giving a quick summary and a link is exactly the right thing to do. \$\endgroup\$
    – mattdm
    Feb 7, 2011 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.