Page 1 of 1

Losslessly remove chrominance channels iff JPEG is grayscale

Posted: 2017-12-29T01:15:51-07:00
by cow10
Is there a way of losslessly reducing a JPEG image's bit-depth to 8 if it's already in grayscale?

Code: Select all

magick convert image image
losslessly chooses the appropriate bit-depth for a grayscale PNG but results in recompression for JPEG. I'm currently using

Code: Select all

jpegtran -grayscale -outfile tmpImage
and checking to see if

Code: Select all

magick compare -metric rmse image tmpImage NUL
is "0 (0)" before replacing the image, though I'd prefer an IM-only solution if possible.

Re: Losslessly remove chrominance channels iff JPEG is grayscale

Posted: 2017-12-29T03:45:17-07:00
by snibgo
IM is a general-purpose raster image processor. So it reads a file and decompresses it, processes the image, then compresses and writes a file. If the output format is JPEG, this will almost certainly be lossy.

Some operations on JPEG can be lossless, but only by doing those operations with intimate knowledge of how JPEG works. IM doesn't do that. Specialist programs such as jpegtran do.