The Compress Jpeg standard was created in 1986 to make on-screen graphics work well on monitors that couldn’t deliver high resolution. It uses lossy compression to reduce image size, which means some quality is lost in the process.
It works best for photographs and pictures of realistic scenes that have smooth variations in tone and color. It’s also widely used on the web, where compressing images is important for responsive design and bandwidth saving. It is less well suited to line drawings and other textual or iconic graphics, where artifacts can be noticeable.
Behind the Pixels: Exploring the Science of Compression with Compress JPEG
The JPEG algorithm first transforms the original image into a Y’CbCr color space. Unlike the RGB color model that uses separate channels for red, green, and blue brightness components, Y’CbCr has an upper limit on the range of colors that can be represented in a single bit. Then the photo is encoded by applying run-length encoding to each component of the Y’CbCr representation. The run-length encoding is based on the assumption that adjacent pixels have similar frequencies, which can be grouped together into a small number of “codewords.” The codewords are then combined using Huffman coding to produce an 8-bit integer representing the image component.
The final step in the encoding is to discard some of the Cb and Cr information. This is called downsampling and can be a good way to further reduce file size. The standard allows a choice of keeping all the colour information, half of it or a quarter of it (this demo keeps all of the information). This is an optional feature that reduces file size by about 5-7%.