New "Guetzli" Technique Saves 35% More Space
Google has announced a new JPEG compression technology that they claim saves up to 35% more space over previous compression techniques. Codenamed “Guetzli,” (“cookie” in Swiss German) this new open source algorithm promises to push more pixels into fewer bytes.
But how does it work? First, let’s consider the existing JPEG standard, commonly implemented online as libjpeg.
How Does JPEG Compression Work?
JPEG is a form of lossy image compression designed specifically for photographs. As such, much of its magic is loosely based on the psychovisual model of human color perception.
By exploiting natural imperfections in the way humans perceive color and form, the libjpeg algorithm can find and discard less-important visual information while preserving crucial detail, reducing complexity and shrinking overall image size.
Specifically, libjpeg takes visual information that’s hard to discern, like quick transitions in intensity and color hue, as well as “high frequency” data. And because humans are more sensitive to differences in brightness than color, JPEG also throws away some color information, rounding off color values and removing information that we probably won’t miss.
The technical details work like this: first, an image is transformed from the RGB color space to the YCbCr color space. This color space, commonly used in television, is just a different way of representing colors mathematically. But unlike RGB, it’s significantly more compressible. The “Y” channel, which represents the crucial brightness values, remains largely untouched, while the less-important color-bearing Cb and Cr channels are targeted for compression.
After converting color space, the next step is a complex mathematical process called a discrete cosine transform, or DCT. First, the image is split into 8×8 pixel blocks. Then, JPEG uses a technique similar to Fourier transforms to convert the color data into cosine waves and detect high and low-frequency information. It then discards the hard-to-see but data-heavy high-frequency information while preserving the low and middle frequencies.
The final step is quantization. The 8×8 blocks from the previous step are inspected, and the color information is averaged. Certain color information is discarded, merging similar colors together and shrinking the overall number of displayed colors. This final step is the source of both JPEG’s impressive compression power and many of its undesirable artifacts.
How Does Google’s Guetzli Compression Differ?
Google’s Guetzli compression isn’t that different from libjpeg. It sticks with the same color space conversion and DCT as libjpeg but specifically targets the final quantization step for improvements.
According to Google, Guetzli “approximates color perception and visual masking in a more thorough and detailed way,” using a more advanced psychovisual model to make more intelligent space saving adjustments.
Thanks to this breakthrough, Guetzli is able to shrink an image size while still maintaining high visual fidelity. In fact, Google says that human testers preferred the results of the Guetzli algorithm, which produced fewer compression artifacts, to the standard libjpeg compression process.
Most impressively, Guetzli does all this while still retaining compatibility with the existing JPEG standard, meaning browsers don’t need to be modified to support it. This is key to Guetzli’s future: the ill-fated JPEG2000 also offered improved compression ratios, but popular adoption was doomed by a lack of backward compatibility, among other factors.
The only downside is that Guetzli takes more time to run than the libjpeg standard. But considering the increase in space savings and image quality, Google is hoping that designers and developers will start to adopt the new compression standard for their imagery.
If you’re interested in learning more, you can check out Guetzli’s GitHub repo.
By taking advantage of new advancements in the quantization stage of JPEG compression, Guetzli can offer significant space savings while still maintaining image quality. And if the Guetzli standard is widely adopted, it could make load times for web page reduce significantly. This would be especially appealing to Google, which has a vested interest in making the web as efficient and fast and possible.