JPEG Compression Algorithm

This Demonstration shows how a two-dimensional discrete cosine transform works on the image blocks during JPEG compression and how the data is degraded by the quantization matrix. Red points in the graphs on the right side display zeros, which are important for the file size reduction. More zeros give more size reduction but worse image quality. You can choose photos and images with patterns; most of them are difficult to compress by the JPEG algorithm.



  • [Snapshot]
  • [Snapshot]
  • [Snapshot]


The JPEG compression algorithm (which is also used in MPEG compression) is based on the two-dimensional discrete cosine transform (DCT) applied to image blocks that are 8×8 pixels in size. DCT concentrates information about the pixels in the top-left corner of the 8×8 matrix so that the importance of information in the direction of the bottom-right corner decreases. It is then possible to degrade the low information value coefficients by dividing and multiplying them by the so-called quantization matrix. These operations are rounded to whole numbers, so the smallest values become zero and can be deleted to reduce the size of the JPEG.
In the columns from the left you can see: the original image, the chosen block and DCT coefficients matrix, the compressed image, the compressed chosen block and degraded block and its coefficient matrix, a 3D representation of pixels, the DCT coefficients and degraded coefficients and chosen block output—pixels, zigzag coefficients, and zigzag degraded coefficients.
Half of the sample photo is without any compression and the other half is already compressed by the JPEG algorithm. Can you recognize which half is which by eye? Can you recognize it by the coefficients?
[1] Wikipedia, "JPEG." (May 2011) http://en.wikipedia.org/wiki/Jpeg.
[2] International Communication Union, "Terminal Equipment and Protocols for Telematic Services," 1993, http://www.w3.org/Graphics/JPEG/itu-t81.pdf.
[3] J. D. Kornblum, "Using JPEG Quantization Tables to Identify Imagery Processed by Software," Digital Investigation 5, 2008 S21–S25, http://dfrws.org/2008/proceedings/p21-kornblum.pdf.
    • Share:

Embed Interactive Demonstration New!

Just copy and paste this snippet of JavaScript code into your website or blog to put the live Demonstration on your site. More details »

Files require Wolfram CDF Player or Mathematica.

Mathematica »
The #1 tool for creating Demonstrations
and anything technical.
Wolfram|Alpha »
Explore anything with the first
computational knowledge engine.
MathWorld »
The web's most extensive
mathematics resource.
Course Assistant Apps »
An app for every course—
right in the palm of your hand.
Wolfram Blog »
Read our views on math,
science, and technology.
Computable Document Format »
The format that makes Demonstrations
(and any information) easy to share and
interact with.
STEM Initiative »
Programs & resources for
educators, schools & students.
Computerbasedmath.org »
Join the initiative for modernizing
math education.
Step-by-Step Solutions »
Walk through homework problems one step at a time, with hints to help along the way.
Wolfram Problem Generator »
Unlimited random practice problems and answers with built-in step-by-step solutions. Practice online or make a printable study sheet.
Wolfram Language »
Knowledge-based programming for everyone.
Powered by Wolfram Mathematica © 2017 Wolfram Demonstrations Project & Contributors  |  Terms of Use  |  Privacy Policy  |  RSS Give us your feedback
Note: To run this Demonstration you need Mathematica 7+ or the free Mathematica Player 7EX
Download or upgrade to Mathematica Player 7EX
I already have Mathematica Player or Mathematica 7+