# How does Jpeg encoding affect the final file size of 24BPP RGB and 8BPP grayscale image?

The reason I'd like to know this is because of a file size problem. I am trying to reduce an image's file size from converting it from TIFF to JPEG. A user challenge me that he notice a RGB TIFF image is three times the size of the same image but in grayscale TIFF version, but the post-convert grayscale version of the JPEG image is almost the same size as the RGB JPEG version.

He insist that a 8BPP grayscale jpeg should have ~1/3 of the size of the 24BPP RGB jpeg.

Then I have been told by some technical adviser afterward that JPEG will ever only exist in the form of 24BPP file, and that the grayscale jpg images I found online are all lying in their image meta data saying bit depth is 8. But so far I haven't found any proof online that confirm nor deny that claim.

At this point I have no idea if my conversion method is flawed and inflated the file size, or the fact that the so call "8BPP JPEG that takes only 1/3 of the file size" doesn't exist from the beginning.

Is there any documentation regarding this issues online?

• bits per pixel is a strange notion when talking about JPEG. And, JPEG usually doesn't work on RGB images, but on a different color model (that's not inherent to the JPEG standard, but none of the JFIF files (which is the usual container for JPEG) I've ever encountered used RGB). Anyway, it makes little sense to argue with someone who's not there, so I'd kindly recommend that you ask your question in more of a constructive manner: How are images of different bit depths compressed using JPEG? Regarding Documentation: I find the JPEG wikipedia article to be quite OK! – Marcus Müller Apr 13 '17 at 9:07
• thanks for the comment. I've realize how unclear my question is and it doesn't solve my ACTUAL problem. I've edited my question and will be glad if you can give me some additional advice. I've also glace through the wiki page before asking the question but I can't find anything related back then, I'll take a look and see if i can dig up anything else. – Jacky Cheng Apr 13 '17 at 9:46

Take a standard R-G-B coded 24-bit image. First, suppose that all channels are coded independently. If by chance, R, G, and B are equal, each one will be converted to the same JPEG file with size $s$.

But such an image would be visually grayscale. The corresponding JPEG compression of the grayscale would be about 3 times smaller (taking headers, etc. into account).

But in JPEG (and most image compression formats), color channels are not treated independently. They are first decorrelated into one luminance (L) and two chrominance images (U, V). If all channels were equal, ie if the image were grayscale as above, Y is the natural grayscale, U and V are zero. The latter two are compressed with almost zero-size, while the luminance is just JPEG compressed.

So, an all gray 24-bit image and the corresponding 8-bit grayscale are JPEG compressed almost the same. In natural images, RGB channels slightly differ:

So if you convert them to YUV (luminance-chrominance), you get:

Typically, the luminance one remains almost 8-bit in dynamics, while the two chrominance ones are flatter, on 4-5 bits. The two latter can be compressed more heavily, as they can be downsampled (they look more low-pass) and amplitude-quantized.

Hence, to the first order, the most of the information is concentrated on the luminance part. So, if the channels do not differ too much, compressing the RGB or the grayscale with JPEG, for sufficiently high rations, is about the same.

• Well explained! Exactly what I need, structured and worded nicely for some novice like me. So if I understand correctly, both my grayscale and color image were convert to YUV domain before compression. And because my test image was a document with ~15% of it actually contains color other black and white, the UV portion of both image are actually fairly small / zero after the jpeg(90%) compression. So the majority of the file size are contributed by Y, and since both my images are basically the same except the color part, Y should be identical and so the final size of both image will be same. – Jacky Cheng Apr 19 '17 at 2:24
• Channel decorrelation is generally a first step in compression, either lossy or lossless. I have seen original grayscale images where the R, G, and B were exactly the same. So your interpretation seems fine to me. To be sure however, you can extract the channels, and check the luminance/chrominance conversion – Laurent Duval Apr 19 '17 at 7:56

For TIFF, one could use different compression formats such as: LZW (makes a png-like size), JPEG (makes a jpeg size) or no-compression (like bmp). Therefore I will look into the compression techniques rather than TIF format.

Jpeg is a compressed image format. In a couple words, it cleverly reduces the high frequency components which do not explain much of the data by quantization. Because of this non-linear compression operation it is very unlikely that you will preserve the bit per pixel ratio (your image content should be very particular for you to have this).

Having said that, the grayscale jpeg do exist of course. You could use the nice and simple Irfanview to save images in grayscale-jpeg form. I have done an experiment in Irfanview for Lena image to show the behavior of different compression levels and file formats:

Compression level is indicated as subscript and for 'png' 9 denotes the best compression rate (taken from Irfanview).

Note that the only format which has the expected $1/3$ ratio in bpp is bitmap and that is only because it is not compressed (basically all pixels are written in a binary file). As the compression approaches zero-loss the color/grayscale gap enlarges. Thus, it becomes visible that compression algorithms are quite successful in handling different color channels. This must not be seen as a performance failure, but rather as a performance boost when the image has 3 channels.

To further gain some compression/quality increase, one could use JPEG2000 format.

For reference, here is the image I use:

• Thank you for the answer! It is very helpful to have some results for me to reference on when I am trying to understand the problem. I was using JPEG90 so it confirms my result. But I feel like your post mostly revolve around confirming that grayscale and color image will end up with similar size, but didn't expand enough on why it happens, which is what I need to truly understand the situation. That said, it is still a great answer in and of itself, thanks! – Jacky Cheng Apr 19 '17 at 2:07