We have an uncompressed image that uses 46 megabytes of space, and a compressed JPEG version of the same image that uses just 4.1 megabytes. Can you see the difference? What about when we zoom in to see the individual pixels? In this article, we will take a deep dive into the JPEG algorithm to see how images can be compressed to just a tenth of their uncompressed file size, all while maintaining the same image resolution and high-quality appearance.
JPEG analyzes each section of an image and removes elements that the human eye cannot easily perceive. When compressing an image via JPEG, you can use a sliding scale called "quality" to decide how much you want to compress the image. As the quality decreases, the file size decreases, but artifacts may become noticeable.
The original image is composed of pixels that have red, green, and blue components (RGB values). Each pixel's RGB values are converted into luminance (Y), blue chrominance (Cb), and red chrominance (Cr) values.
Human eyes are more sensitive to luminance than chrominance. In this step, we divide blue and red chrominance component images into 2x2 blocks, find the average value for each block, and shrink the image. This removes a considerable amount of data.
These steps remove information that our eyes aren’t good at perceiving, like high-frequency elements. In DCT, we transform each 8x8 pixel block into 64 values. In quantization, we divide these values by elements in a quantization table and round them, leaving a lot of zeros in the data.
We list all the values for every block using a zigzag pattern to maximize the number of zeros. These zeros are then replaced by a simpler representation. Huffman encoding further compresses this data using a binary tree.
To uncompress the image, we reverse the steps: decode the Huffman encoding, multiply the values back with the quantization table, add the base images together, and finally convert the Y, Cb, and Cr values back to RGB.
In conclusion, the JPEG algorithm leverages human visual perception limitations to achieve impressive compression rates without noticeable loss in quality. Whether for digital photography or web images, understanding JPEG helps us appreciate the complexity behind a seemingly simple action of saving a picture.
JPEG compression involves color space conversion, chrominance down sampling, discrete cosine transform (DCT), quantization, and encoding (run length and Huffman encoding). It removes data that the human eye cannot perceive well, thus reducing the file size.
JPEG is widely used because it offers a good balance between image quality and file size. It's versatile enough for most digital photography and web use cases.
Chrominance down sampling reduces the color information in the image. Since human eyes are less sensitive to color details, JPEG compresses the blue and red chrominance channels to save space.
Artifacts are visual distortions that appear in highly-compressed JPEG images, often looking like blocky or blurry areas. They occur when too much information is discarded during compression.
In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.
TopView.ai provides two powerful tools to help you make ads video in one click.
Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.
Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.