image-processingimagemagickjpegmogrify

Jpeg, remove chroma, keep only luma without recompressing?


Is it possible to strip down chroma information from a jpeg file without loss on the luma?

Ideally I'd like a smaller file-size, greyscale version of an existing and optimized image.


Solution

  • Use jpegtran’s -grayscale option. From the manual:

    This option discards the chrominance channels if the input image is YCbCr (ie, a standard color JPEG), resulting in a grayscale JPEG file. The luminance channel is preserved exactly, so this is a better method of reducing to grayscale than decompression, conversion, and recompression. This switch is particularly handy for fixing a monochrome picture that was mistakenly encoded as a color JPEG. (In such a case, the space savings from getting rid of the near-empty chroma channels won't be large; but the decoding time for a grayscale JPEG is substantially less than that for a color JPEG.)

    Example:

    jpegtran -grayscale -outfile luma.jpg input_image.jpg