Is re-encoding JPEG images an idempotent operation?

独自空忆成欢 提交于 2019-12-19 06:40:29

问题


I am aware that JPEG compression is lossy. I have 2 questions:

Given an operation T:
1. Take a JPEG-80 image
2. Decode it to a byte buffer
3. Encode given byte buffer as JPEG-80

Is T an idempotent operation in terms of visual quality? Or will the quality of the image keep degrading as I repeat T? Does the same hold true for the JPEG-XR codec?

Thank you!

Edit: Since there have been conflicting answers, it would be great if you could provide references!


回答1:


It's not guaranteed, but it may happen. Especially if you repeat the encode -> decode -> encode -> decode process enough times, it will eventually settle on a fixpoint and stop losing quality further (as long as you stick to the same quality and same encoder).

JPEG encoding is done in several steps:

  1. RGB to YUV conversion
  2. DCT (change into frequency domain)
  3. Quantization (throwing away bits of the DCT)
  4. Lossless compression

And decoding is the same process backwards.

Steps 1 and 2 have rounding errors (especially in speed-optimized encoders using integer math), so for idempotent re-encoding you need to be lucky to get encoding and decoding rounding errors to be small or cancel each other out.

The step 3, which is the major lossy step, is actually idempotent. If your decoded pixels convert to similar-enough DCT it will quantize to the same data again!

JPEG XR also uses YUV, so it may suffer some rounding errors, but OTOH instead of DCT it uses a different transform that can be computed without rounding errors, so it should be easier to round-trip JPEG-XR than other formats.




回答2:


By definition, a lossy operation discards data by simplifying the representation in a way that (ideally) isn't noticeable to the end user. However, the encoder has no magic method for determining which pixels are important and which aren't, so it encodes all pixels equally, even if they are artifacts!

In other words, the encoder will treat the lossily-compressed image the same as a lossless image. The lossy image will be further simplified, discarding additional data in the process, because for all the encoder knows, the user intends to represent the artifacts.

Here are some examples of JPEG generation loss:

http://vimeo.com/3750507

http://en.wikipedia.org/wiki/File:JPEG_Generarion_Loss_rotating_90_(stitch_of_0,100,200,500,900,2000_times).png



来源:https://stackoverflow.com/questions/14841834/is-re-encoding-jpeg-images-an-idempotent-operation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!