Serene Life

by garik

submit your photo


Hall of Fame
View past winners from this year

Please participate in Meta
and help us grow.

Take the 2-minute tour ×
Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

up vote 2 down vote accepted

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.

share|improve this answer
    
These patterns seem to refer to frequency sampling for video, not JPEG encoding. –  whuber Feb 5 '11 at 21:42
    
@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. –  Jerry Coffin Feb 5 '11 at 22:15
1  
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. –  thomasrutter Feb 7 '11 at 13:20
    
@thomasrutter, Photoshop picks the subsampling based on the quality setting you choose. It's not an independent option. –  Mark Ransom Feb 8 '11 at 4:39
    
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. –  thomasrutter Nov 15 '12 at 23:59

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.

share|improve this answer
    
This was stated in the question. Provide a more detailed answer. –  Nick Bedford Feb 7 '11 at 8:33
    
@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). –  whuber Feb 7 '11 at 13:25
    
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. –  mattdm Feb 7 '11 at 14:27

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.

share|improve this answer

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.

share|improve this answer
1  
I think my brain just exploded. –  Nick Bedford Feb 7 '11 at 8:31
    
Chroma-subsampling doesn't just result in "loss of resolution". It introduces very noticeable artifacts especially in the red channel. –  Mark Ransom Feb 8 '11 at 4:43
    
@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. –  thomasrutter Feb 8 '11 at 5:20
3  
I don't think I've ever seen a better, easier to understand explanation of jpeg - or really lossy - image compression. definite +1 –  jay.lee Feb 8 '11 at 11:16
    
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. –  Mark Ransom Feb 11 '11 at 3:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.