97

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?

koan
  • 3,596
  • 2
  • 25
  • 35
Sugrue
  • 3,629
  • 5
  • 35
  • 53

4 Answers4

81

As correctly answered above, using a "typical" JPEG encoder at quality 100 does not give you lossless compression. Lossless JPEG encoding exists, but it's different in nature and seldom used.

I'm just posting to say why quality 100 does not mean lossless.

In JPEG compression information is mostly lost during the DCT coefficient quantization step (8-by-8 coefficient blocks are divided by a 8-by-8 quantization table, so they become smaller --> 'more compressible'). When you set JPEG quality to 100, no real quantization takes place (because the quantization table will be all 1s, at least with standard IJG-JPEG tables), so in fact you don't lose information here..

However, there are mainly two factors leading to information loss even when no quantization takes place:

  1. Typically, JPEG compression reduces color information (becase 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. Nevertheless, JPEG encoding implies going to the DCT domain, which causes rounding of coefficients. Rounding discards some information. This will happen regardless of all other options.
Marco Fontani
  • 946
  • 7
  • 5
69

Jpeg is lossy regardless of the setting. At 100, you just get the LEAST loss possible.

It's easy enough to test. Whip up a simple .bmp, compress that to a q=100 jpeg, then re-extract back to a .bmp. Use Gimp/Photoshop to do a "difference" of the two bitmaps, and you'll see the lossiness - it'll be much less noticeable than on a q=50 or q=1 conversion, but still be present.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • 9
    As an alternative, JPEG2000 supports a lossless mode. – schnaader Nov 04 '11 at 02:45
  • 3
    @MarcB, How would you *"use Gimp/Photoshop to do a "difference" of the two bitmaps"*? – Pacerier Aug 19 '15 at 23:36
  • 15
    @Pacerier, with gimp, you open the reference image, then "open as a layer" the second one. From the "layer" toolbox, you can choose the "difference" overlay method. And if you flatten the image as this, and stretch the contrast, et voilà ! – yota Aug 26 '15 at 05:58
23

There is a lossless form of JPEG but it is not widely supported and you do not get it by tweaking the quality setting - it's an entirely different process.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • 2
    So why is it called JPEG? – Pacerier Apr 13 '17 at 02:59
  • 6
    @Pacerier good question. It's because it was developed by the Joint Photographic Experts Group, the same people that made the original JPEG. I have no idea why they tried to piggyback it on the earlier spec instead of creating a new one as they did with JPEG-2000. – Mark Ransom Apr 13 '17 at 03:09
  • 4
    Aditionally, the name of the image standard we know as JPEG is actually JFIF. Related: https://stackoverflow.com/questions/1427623/are-all-jpeg-files-jfif – Glen Davies Jun 24 '19 at 14:16
-1

According to wikipedia, No.

jpeg 100 has a compression ratio of 2.6:1. The compression method is usually lossy, meaning that some original image information is lost and cannot be restored, possibly affecting image quality.

There is an optional lossless mode defined in the JPEG standard; however, this mode is not widely supported in products.

Pacerier
  • 86,231
  • 106
  • 366
  • 634
Mark Price
  • 582
  • 1
  • 8
  • 18
  • 18
    Just because it has a compression ratio does not make it lossy. You can compress with out losing quality... PNG/GIF? – IAmGroot May 22 '12 at 13:40
  • 4
    The compression method is usually lossy, meaning that some original image information is lost and cannot be restored, possibly affecting image quality. There is an optional lossless mode defined in the JPEG standard; however, this mode is not widely supported in products. – Mark Price Jun 22 '12 at 10:09
  • 2
    You should add that to your answer. It is a much better explanation as to why it is lossy - rather than just stating it has a compression ratio :) – IAmGroot Jun 22 '12 at 11:03