Search code examples
jpeglossless-compression

Is JPEG lossless when quality is set to 100?


I understand that JPEG is a lossy compression standard, and that the 'quality' factor controls the degree of compression and thus the amount of data loss.

But when the quality number is set to 100, is the resulting jpeg lossless?


Solution

  • Using a "typical" JPEG encoder at quality 100 does not give you lossless compression.1

    In JPEG compression, information is mostly lost during the DCT coefficient quantization step. That is, 8-by-8 coefficient blocks are divided by a 8-by-8 quantization table, so they become smaller, and thus 'more compressible' after rounding.

    When you set JPEG quality to 100, the DCT coefficients are unchanged except for rounding. This is because the quantization table will be all 1s with the standard IJG-JPEG tables.

    Thus, there are mainly two factors leading to information loss when quality is 100:

    1. Chroma subsampling. Typically, JPEG compression reduces color information (because the human visual system is less senstitive to that than to lumimance). Therefore, even at quality 100 you may be carrying out chrominance subsampling (which means, dropping half or more Cb and Cr coefficients). When this happens, information is lost, even when no quantization happens. However, you can tell the encoder to preserve full chromimance (so called 4:4:4 color sampling).
    2. Rounding. The DCT coefficients are rounded to integers, and then losslessly encoded into the output JPEG file. Rounding discards some information. This will happen regardless of all other options.

    1 Lossless JPEG encoding exists, but it's different in nature and seldom used.