# How Does Color Conversion and Downsampling work When JPEG compressing a grayscale image?

For color images I know you have to convert to YCbCr format, and then for downsampling is based on the fact that human beings see differences in Y more than differences in Cb or Cr.

How do I do these things but for grayscale (or monochrome) images?

• Y is the grayscale channel. Just ignore the Cb (Color blue) and Cr (Color green). Why no Cg (Color green)? Because it is redundant mathematically. Jun 29, 2020 at 15:56

Normally, monochrome images should be stored as images with a single channel. However, I have seen digital images with three channels containing the same values. This results in a displayed image looking grayscale.

Before compression multichannel data, it is common to decorrelate the channels. For RGB, one often concert them to luminance and chrominances. Several formulae can be seen, linear and nonlinear, to convert $$R$$, $$G$$ and $$B$$ to $$L$$ and the two $$C_x$$:

$$L= \mathrm{c2l}(R,G,B)$$ and $$C_x= \mathrm{c2r}_x(R,G,B)$$

In most cases I know, for the same repeated channel (say $$R$$, but whatever),

$$L= \mathrm{c2l}(R,R,R)\simeq R$$ and $$C_x= \mathrm{c2r}_x(R,R,R)\simeq 0$$ so the compression code will naturally "cancel" the unnecessary channel triplication for a grayscale image. As a side node, this can be the cause of errors in computing compression ratios, as the original image is three times the size it should have been. This uses to happen in monaural (mono) audio stored on two duplicated stereo channels.

To be more concrete, with the classical linear YUV conversion:

Y =  0.299R + 0.587G + 0.114B
U = -0.147R - 0.289G + 0.436B
V =  0.615R - 0.515G - 0.100B


and since:

 0.299 + 0.587 + 0.114 = 1
-0.147 - 0.289 + 0.436 = 0
0.615 - 0.515 - 0.100 = 0


one can see that the chrominance images are zero (or close to zero for nonlinear transforms), and remain very small in amplitude after DCT and subsampling, and will be unnoticeable in JPEG compression.

JPEG will typically encode the single grayscale as a single color-channel.

Ther might be strange applications out there that will expand the grayscale image into rgb, then matrix to YCbCr, then call jpeg encoder, but I don't see why it would do that, other than to overcome buggy decoder implementations.

I will share my experience in image optimization ... At first, I had to manually compress all the pictures through Photoshop. The most free option by the way (except for the cost of a license for Photoshop). But this process takes a lot of time if there are more than 10-20 pictures on the site. After all, each picture must be manually processed, and then upload on the site again. Tedious such a process ... Now I use this service - https://optipic.io/ It saves a lot of time) It works by itself - automatically - only 1 time it needs to be connected to the site. Google is satisfied)