1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Cedron Dawg Jun 29 at 15:56
1
$\begingroup$

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.

| improve this answer | |
$\endgroup$
0
$\begingroup$

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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.