Evening

by w.hrybok

submit your photo


Hall of Fame
View past winners from this year

Please participate in Meta
and help us grow.

Take the 2-minute tour ×
Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

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?

share|improve this question
    
Some answers for pieces of this question exist here: photo.stackexchange.com/questions/5317/… –  dpollitt Jan 16 '12 at 16:32
    
Thanks @dpollit. I didn't see that one due to the British spelling and lack of tags. Plus, it's is very specifically about low-resolution and low file size. –  mattdm Jan 16 '12 at 16:38
1  
I would direct you to my answer on the topic @dpollit linked before, specifically the web site linked from it, which has a whole load of sample images from every major "quality" level, with pixel-level detail, for a variety of types of images. –  jrista Jan 16 '12 at 18:32
1  
Thanks @jrista. That's a lot of what I was looking for. –  mattdm Jan 16 '12 at 22:03
1  
@BBking — I'd love to see an answer elaborating on that, with references. –  mattdm Nov 8 '12 at 11:29

6 Answers 6

up vote 13 down vote accepted
+50

An example

Using the current photo of the week image. This is the high-quality JPEG:

gimp Q=99

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:

gimp Q=80

and re-saved in GIMP with JPEG quality 30 (very low); please note evident 8x8 blocks and severe loss of sharpness and color detail:

gimp Q=30

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):

three-way compare

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)
share|improve this answer
    
links to your images are broken, are you able to relink/reupload them? –  MikeW Feb 8 '13 at 22:15
    
@MikeW Thanks for pointing out. I re-uploaded them. –  sastanin Feb 8 '13 at 23:50

JPEG actually uses two types of compression, a lossly and a lossless one. Lossless compression doesn't cause artifacts, so we can ignore that part. The particular type of lossy compression in JPEG, called a discrete cosine transform for the math knurds, allows a tradeoff between compression ratio and fidelity. Most software sufaces this as a "quality" value, ususally on the 0-100 scale with 100 being effectively no or very little loss and things going down from there.

This particular compression algorithm was adopted because it's good at throwing out the kind of things the human visual system doesn't notice as much as other scene components. This is in part why pretty decent looking pictures can have impressively high compression ratios. This is also why it works well on real continuous tone photographs and not so well on synthetic images and line art.

Here is a 200 x 300 region of a larger photograph with the pixels replicated 2x to see them better. This used JPEG compress "quality" 100:

Quality 80, 79% file size reduction:

Quality 60, 86% reduction:

Quality 40, 90% reduction:

The file size reductions were based on JPEG compressions of the whole file so that header structures and other fixed overhead was a small portion of the data.

Notice that you have to look to find artifacts in the second picture, even though nearly 4/5 of the original information was tossed out. JPEG compression artifacts are usually most visible at sharp edges and in slowly changing flat areas. Since line art is all sharp edges, JPEG compression is not appropriate for that.

You can see the compression artifacts getting progressively worse at higher compression ratios. Keep in mind though that the bottom picture retains a amazing amount of the visual information for having 9/10th of its raw information deleted.

The types of artifacts characteristic of JPEG lossy compression are "blockiness" in slowly changing flat areas and "dirt" surrounding high-contrast edges. For example, see the bottom right area in the picture above. That contains out of focus background, so the values are changing slowly. The blockiness is quite evident. For examples of the "dirt", look around the goat's left horn. These two types of artifacts are usually a strong clue that JPEG compression was envolved. Also look for these in the other pictures above to get a sense for what they look like when they just start to appear, and what kind of compression ratio you might be able tolerate in various circumstances.

share|improve this answer

JPG compression is done in blocks of pixels. In a highly compressed JPG image the edges of those blocks can be seen: in the original image two pixels may have been very close in brightness and color, but if they are in different blocks, then after compression and decompression (when viewed) each of their values may differ from the original, so you lose that gradual blending and start to see this "blockiness".

enter image description here

Here is a typical example in a sky - JPG saved at 0 quality.

If you are uploaded to a site that uses JPG compression you may have better results doing two things (you'll need to experiment with the site to see what works):

  • resize the dimensions of your image to be within the maximum height/width allowed by the site, so the website doesn't resize your images for you

  • do your own compression to get a smaller file size with good quality. Depending on how the site works, if the image is already small enough it may not do any further compression, or even if it does, it may have a lesser effect.

As far as removing JPG artifacts from an image, JPG artifacts can look similar to normal sensor noise. Noise reducing software will be somewhat successful at removing some minor JPG artifacts, but at the loss of detail.

noise like jpg artifacts

Here is an example with JPG quality of 50%, with blockiness, but also darker and brighter pixels which resemble noise.

Topaz Labs have a product called DeJpeg, which acts specifically on JPG artifacts. It does a good job of this without too much loss of detail. The plugin also can also do some sharpening and general noise reduction. The plugin is compatible with Photoshop CS, Photoshop Elements, and Paint Shop Pro. I don't think it works with Lightroom or Aperture.

share|improve this answer
    
Can you give an example of a jpeg artifact which appears similar to sensor noise? –  mattdm Jan 17 '12 at 0:02
    
Have added one of a dark sky saved at 50% JPG quality. –  MikeW Jan 17 '12 at 21:26
    
Thanks, that's useful! –  mattdm Jan 17 '12 at 21:31

For websites which compress files until they reach a certain target filesize there is a way you can improve the quality of images in certain circumstances.

JPEG works by converting the image into a [series of] frequency space representation[s] (where X and Y represent horizontal and vertical frequencies, and "brightness" represents the amplitude of the frequency). Frequencies below a certain amplitude are ignored, reducing the amount of data that is stored, achieving compression.

Noise has a broad spectrum of frequencies that is JPEG can't compress. That's why you can have two images, apply the same level of compression, and get two different filesizes after JPEG compression.

If you take your image and intentionally blur the unimportant background areas, you reduce the total amount of information and achieve much higher compression of these areas, leaving you more kilobytes to encode the areas where detail is important. This works particularly well with images in which the background is already out of focus.

share|improve this answer

Here is an example of a magnified jpeg:

enter image description here

Image by Wikipedia user FelixH. This image is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.

In this image you can clearly see the so called "artifacts" in the blue area. Note how the image appears to be divided up in blocks, and the block boundaries do not match.

There are a number of things that can be done to avoid or reduce this problem:

  • The most obvious: do not use jpeg. You may want to work with your images using a lossless compression format, like RAW, PNG or lossless TIFF. You only downgrade to jpeg in the last step, when you want to upload the picture to the web, email, etc.

  • The jpeg format allows for configuration of compression level. You can get less artifacts if you want, but the file will be bigger.

  • Avoid re-saving a jpeg over and over, as each generation degrades the quality even more.

share|improve this answer
    
Even RAW and PNG can get artifacts due to pixel quantizing. As long as you don't change any values, that's just a one time effect and no further losses happen due to digitization. However, if you change the values at any step, like darkening or lightening a scene, or blending with other values, etc, then the value shifts can result in new artifacts at the next save (even without compression) due to the quantizing (arguably a form of compression) to save the new calculated image. To minimize these effects, use the largest number of bits possible at every step, and keep your entire workflow. –  Skaperen Jan 16 '12 at 21:36
    
@Skaperen: you are confusing two different things here. This question is about loss of detail due to jpeg compression. What you are describing is loss of detail introduced by certain image processing algorithms. What you are describing is correct, but is not related to image formats at all, so saying that RAW and PNG are associated with pixel quantizing is wrong, those file formats do not cause any loss of quality. –  Miguel Jan 17 '12 at 1:02
    
This image also demonstrates another issue, by the way: it shows a halo from unsharp mask. –  mattdm Nov 12 '12 at 14:02

Artifacts are the unwanted side-effects of processing an image. In this case, they result from the way data is compressed by the JPEG algorithm.

Generally people want to be able to store photos digitally, without using too much storage space. As a result, most photos are stored in the JPEG format. This is a format that compresses the data that makes up the image in a way that attempts to preserve as much detail as possible. The level of compression can be changed when the file is created. However, it is a "lossy" algorithm, which means it discards some data - it's not possible to go back from a compressed JPEG file to the original data.

This loss of data comes at the expense of image quality. The compression is designed to create minimal impact on the overall image, but can be noticeable at high compression levels.

JPEG artifacts most commonly look like blocky sections of colour. They can be seen where there is a subtle graduated colour change in a large wash of colour - e.g. in a blue sky, or a foggy scene. The artifacts look like jagged outlines of a specific colour rather than a smooth blend.

With more highly compressed scenes, artifacts can also be seen around the borders of subjects - e.g. a tree's branches against a light sky. These look like blotchy blocks surrounding the subject.

The best approach for reducing artifacting is:

  1. Always keep the original image - don't save a compressed JPEG, then re-open it later and re-save. For an extreme example of this, see Generation Loss, a video showing an image re-compressed 600 times.
  2. Save as high quality as possible, given any file size restrictions.
  3. Avoid using services which severely re-compress your images - if necessary host them elsewhere and link to them directly.

For more information see http://photo.net/learn/jpeg/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.