I know JPEG is a "lossy" compression algorithm that discards information in order to save space. What is the visual impact of this? I've heard of "JPEG artifacts". What do these look like?
Are there situations where the same level of compression creates more artifacts and looks worse? Does the content of the image matter at all? What does the algorithm handle well, and what does it have trouble with?
Assuming JPEG is a requirement, is there a way to reduce artifacts? If I'm uploading to a web service which will apply its own compression outside of my control, is there anything I can do to the image in advance to make it survive this better?
Answer
An example
Using the current photo of the week image. This is the high-quality JPEG:
re-saved in Gimp with JPEG quality 80 (low); please note the general loss of sharpness, "dots" around high-contrast edges, loss of detail in low-contrast areas:
and re-saved in GIMP with JPEG quality 30 (very low); please note evident 8x8 blocks and severe loss of sharpness and color detail:
Three kinds of distortions
JPEG tends to introduce two three kinds of distortions:
- general loss of sharpness and oscillations around high-contrast edges: these are due to approximating intensity transitions with smooth functions (cosines); you see them as small "dots" or "halos" around the edges; they are particularly easy to see in the images of text of hand-drawings.
- blocking structure: image is processed separately for every 8x8 block (or bigger in case of chroma downsampling), block edges become visible at high compression ratios.
- loss of color detail: it depends on saving parameters, the program may aggressively "downsample" (reduce resolution of) chromaticity channels; it is rarely an issue for the natural photography.
Visible block structure and halos around edges are usually referred to as JPEG artifacts. Let's zoom in our example to see them better. From left to right, a crop from the original, JPEG Q80 and JPEG Q30 images. I marked artifacts in green (circles for halos, and dots for 8x8 blocks):
As any information loss, you cannot actually recover it. Sharpening may help to recover lost edge contrast, but makes "halos" more evident; denoising may help to remove "halos", but reduces sharpness even further. If block structure is visible, it is probably too late. Just keep the original high-resolution, high-quality images around, and don't overwrite them.
Hosting strategies
If you control JPEG compression parameters and want to maximize image quality:
- keep the compression ratio as low as you can (use high-quality settings)
- consider downsampling chromaticity channels (it may be almost unnoticeable for some images, and allows for lower compression ratio in the luminosity channel given the same file size constraint)
- consider using floating-point discrete cosine transform (it may increase precision of the transform, but file saving will take longer)
- consider using lower resolution instead of higher compression ratio (given the same bound on the file size)
If you upload to a third-party service, and don't control compression parameters, you cannot do much about it:
- choose a service which is known to prefer high-quality JPEG (Flickr, SmugMug, 23hq, 500px) over services which are known to over-compress to save traffic (Picasa, Imgur, Dropbox); usually you get what you pay for.
- try resizing photos yourself and uploading the right size (some services will re-compress it anyway, some may serve your file as uploaded)
No comments:
Post a Comment