Home ›› The Basics ›› JPEG – Know thine enemy
JPEG – Know thine enemy

Last update:  12-31-1969

Submitted by byRo

It’s worth a few minutes to find out how this works.

This tutorial is Copyright © byRo, who has sole responsiblity for its content.
Have a question for the author? Or simply want to discuss this topic further? Click "Discuss" up at the top. If you'd like to publish a tutorial of your own, simply click on "Publish" over on the menubar.


Overall Recommendation





Expertise     8.5
Utility     5.8
Clarity     6.5
Relevance   7

JPEG was invented as a way to compress a normal photo into a much smaller file without losing important parts of the image. As such, for those who will be just looking at the photo on a monitor the quality is quite acceptable – even when applying very large compression ratios.


On the other hand, the folks around here are going to do just about everything with a photo but just look at it.


We all know that the use of JPEG will always introduce distortion into a photo and.......

..wait a minute. Look at this image:


This was saved with JPEG quality 0 (zero) and there is not one pixel out of place! ( Why? *1)  Seems like we have some things to learn here...


JPEG – how does it work (slightly simplified)

The JPEG process has several stages, we’ll take each one in turn and then we’ll see what it means to us.

1) Separate the Luminosity

Just like we often do in retouching, the first step is to separate out the luminosity. JPEG does this by combining a percentage of the three color channels:

Green 59%, Red 30%, Blue 11%.

Which, by no coincidence at all, is the same luminosity ratio used by Photoshop.


2) Make blocks

JPEG takes the luminosity image and divides it into little (little, if the image is big) blocks of 8 by 8 pixels. This is important so let’s say it again: Starting from the top left corner, JPEG marks out 8 x 8 blocks. Thus we know for certain that the point at the coordinates 160,480, for example, is always going to be the start of a block.


3) Transform the 8 x 8 blocks

This is where the tricky maths comes in: The distribution of the luminosity values of the 64 pixels in the 8 x 8 blocks is transformed into a different representation, using 64 frequency components (*2). Up to this point we can still get back from here exactly to the original image – but we also haven’t compressed anything yet.


4) Normalizing and JPEG quality

The guys who specified JPEG did a lot of work to figure out which of those 64 frequencies were more important and gave each one a different weight – more for low frequencies, less for high frequencies. The JPEG quality also cuts into the high frequencies – the lower the quality the deeper it cuts. The end result here is that of those 64 frequencies that we had to start with, many, or maybe nearly all, of the higher frequencies have been reduced to zero.


5) Compressing the information

Now comes a pretty standard compression trick to just throw away all the zeros, and save only the relevant information.


6) Repeat steps 2 – 5 for color information

Except that the blocks are now 16 x 16 and not 8 x 8.


7) Finishing Up

Put in the housekeeping information and save as “.jpg”.


If you understood some of this, that’s great. If not, no problem, let’s go on...

Here's what we got with JPEG quality 0.


   Maria at JPEG quality 0





Close-up at JPEG 0

































Luminosity Component                                    Color Component


JPEG – so what?

Now what does this mean to us:

1) Separate the luminosity

·         Poor little Blue channel – no wonder it is usually so noisy, when we open up the JPEG file, only 11% of the luminosity information is used to remake the Blue channel.

·         Also, when we work on the photo by separating the luminosty and color information, we are not inventing anything new – we are just working on the separate JPEG components.

2) Make blocks

·         We’ve seen plenty of them, but now we know exactly where they are.

·         This piece of information can be very useful when we are trying to undo the effects of JPEG.

·         If we have a JPEG image and don’t crop or resize it then, if we save again, the JPEG artifacts will fall in exactly the same place. However, if we change the top left corner and / or resize in any way, saving as JPEG again will introduce more artifacts at different places. 

3) Transform the 8 x 8 blocks

·         Doesn’t affect anything but.....

4) Normalizing and JPEG quality

·         The high frequencies get eliminated. High frequencies => sharpening => edges. As the JPEG quality goes down we lose the definition of the edges. If the edge information isn’t there any more, no amount of sharpening is going to fix this – we’ll just get more and more JPEG noise.

5) Compressing the information

·         No effect on the image

6) Color information

·         JPEG occupies very little space with color information. This means that when you save a grayscale image you don’t get a file 1/3 the size, instead it’s pretty much the same.


Well, that’s enough for now.

Next up: Cleaning up JPEG’s



(*1) Why – Because the luminosty information of this particular (contrived) image occupies entire blocks of 8 x 8 and the color information entire blocks of 16 x 16. If we take the same image and crop out a 4 x 4 top left border the whole thing falls apart and the JPEG artifacts set in.....










(*2) The Discrete Cosine Transformation – Fast Fourier’s kid brother.