How can I demonstrate JPEG quality loss from repeated saving or different compression settings?
Asked 1/10/2019
38 views
2 answers
0
I'm writing a report about image file formats and want to show how lossy JPEG compression can reduce image quality over time. I tried repeatedly saving the same JPEG under different filenames, but the file size only got smaller the first time and then seemed to stay about the same.
Why doesn't the image keep degrading when I resave it unchanged? Is it being recompressed, or is the encoder preserving the same data when nothing changes?
What is the best way to demonstrate JPEG quality loss clearly for a report: repeated resaving, changing compression quality each time, or making small edits between saves?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
7y ago
2 Answers
3
The JPEG implementations used by most graphics software is designed specifically to prevent degradation when a block is saved over and over if the content does not change. Every 8x8 block will remain the same if re-encoded on the same settings as long as no pixels in the block have been changed.
To simulate this, rack the curves or levels center point up and down a value, or convert from RGB to Lab and back to introduce minor changes that need to be re-compressed.
Some basics on JPEG compression steps and compression vulnerabilityThe process goes through six distinct phases:
Color Space Transformation (1) and Downsampling (2)
The color space transformation and downsampling are usually bypassed in images saved at a high quality. The short explanation is it separates the luminence from the color data, then downsamples the color channels to reduce the raw data load with minimal data reduction. If this is in the process, it's a major source of degradation on re-saves, but most implementations in graphics software will preserve the full-resolution RGB channels.
Block splitting (3)
Block splitting is lossless except at the extreme edges of an image where dummy data is added, but better algorithms will fill in those blocks with data to minimize artifacts when possible. This cuts the images into 8x8 pixel blocks for compression
Discrete cosine transform (4)
In most modern implementations made for image storage, it's steps 4 and 5 that cause the degradation.
Discrete cosign transformation is too complex to describe here in a way that does it justice, but I recommend you read up on it at some point. To summarize any 8x8 block of pixels can be perfectly represented by linear combination of the 64 8x8 blocks shown below. In most photo type images, the broader detail patters are much stronger than the finer detail blocks. This is not a lossy process, but each final value is rounded to only a couple of digits after the decimal.
Quantization (5)
With the values organized in this way, we can take advantage of how the human eye and brain resolve detail, which is that it favors broad detail over narrow detail. This is where most of the compression actually occurs. The lower detail blocks both affect the output less, and that affect is less than noticeable to the human brain, we can just clip some of these smaller values to 0 and ignore them. The quantization matrix is added to the file, every algorithm provides their own, but they are preserved between saves. The raw values are divided by the values in the quantization matrix and rounded to the nearest integer. This rounding is a primary component of the lossiness.
Entropy coding (6)
Entropy coding organized the final matrix from the most significant corner to the least significant corner, generally this groups the 0's at the end of the list. After that, those 0's can be truncated and the results encoded into the file. This, again, is a basically lossless process, but saves a lot of space.
Running a jpeg through this process again, the final compressed blocks will be identical because the removed detail data is not there to be filtered away. Because this is done on 8x8 blocks, this even works on any unedited portions of image that are changed between saves.
Originally by user68136. Source · Licensed CC BY-SA 4.0
user68136
7y ago
0
Generated from our catalog & community — verify before relying on it.
If you resave an unchanged JPEG at the same quality setting, many JPEG encoders are designed to minimize additional generational loss. In practice, the image may be recompressed, but the 8×8 block data can remain effectively the same, so file size and visible quality may change very little.
For a clear demonstration, use one of these methods:
- Start from the original image each time and export multiple JPEGs at different quality settings. This is the simplest way to show how stronger lossy compression affects detail and artifacts.
- If you want to show repeated-save degradation, make a tiny edit before each save so the image must be recompressed differently. For example, slightly move the curves/levels midpoint up and down, or convert RGB to Lab and back before each save.
Also note that image content matters: smooth areas may show little change, while fine detail and edges reveal compression artifacts more clearly.
So: unchanged resaves at the same settings may not visibly degrade much; varying quality settings or introducing small edits is the better way to demonstrate JPEG loss.
Recommended products
UniqueBot
AI7y ago
Your Answer
Related Questions
Why can two JPEGs from the same photo have different file sizes at the same resolution?
What causes JPEG generational loss when a file is re-saved multiple times?
How can I tell whether a TIFF file uses lossy or lossless compression?
How much does Nikon’s lossy-compressed 14-bit NEF affect real-world image quality vs JPEG?
Does opening and closing a JPEG reduce image quality, or only saving it?
