Jpeg files are all over the internet. They are useful because they compress pictures very well. Your web surfing would come to a halt if we had to use the bmp we generated for project 1.

The bmps we created were 24 bits per pixel. A jpeg at full quality settings can use as little as 9 bits per pixel. However, this compression is not without penalty. Some data is thrown away in order to make the file smaller.
Jpeg compression incorporates a clever mathematical property of discrete cosine transforms (a computable version of a Fourier series) in order to make the file as small as possible.
There are 3 basic steps to JPEG compression.
- Downsampling
- Quantization of the discrete cosine transform
- Lossless Encoding
The first step is fairly simple. You can easily reduce a 400×400 image into 100×100 pixels. This will obviously look very blocky if you have tried resizing a picture in paint.
However, jpeg uses the color scheme Y-Cb-Cr instead of R-G-B (red green blue). Humans can discern brightness (Y) much more than they can tell color apart (Cb and Cr), so you downsample the color bits without making the picture look too different.
The second step is much more complicated. The picture is split into chunks of 8×8 pixels. Then a discrete cosine transform is applied to it. This has the effect of turning the pixel matrix into a matrix representing a combination of 64 basis images shown below.
![]()
Each jpeg image is the linear sum of any of these 8×8 basis images.

An example of a 8×8 matrix after undergoing DCT.
Notice how the larger values are concentrated on the top left corner. This is a special property of using DCT instead of a discrete fourier transform, and this is the special trick to make pictures more compressible.
Now we perform quantization, which divides each cell in the DCT matrix by a certain number. Notice in the 64 basis images above, you cannot tell the difference between the squares in the bottom right corner as well as the squares in the top left. The makers of jpeg exploit this fact by dividing by larger numbers as you reach the bottom right cell.

DCT matrix after quantization. Look at all the zeroes. This looks easy to compress now.
Setting your jpeg save quality lower will increase the numbers you divide by, therefore increasing the number of zeroes in the matrix.

Jpeg saved at lowest quality. Can you see the 8×8 basis images mostly made of the squares at the top left hand corner now?
The last step then involves any sort of lossless encoding such as RLE (run length encoding) that would easily compress the numerous repeating zeroes.
Now you can impress your friends with your intimate knowledge of jpegs while ogling facebook pictures.






[…] provided an informative overview of the widely used JPEG image compression format (see post, “A brief overview of Jpeg”). It should however be noted that the JPEG format is not good at compressing all types of images, […]