Image Compression:
How Math Led to the JPEG2000 Standard
Color Images
Compressing color images using the JPEG Image Compression Standard is very similar to the process used to compress grayscale images. In raw format, color images are stored in three matrices. These matrices hold the intensity levels for red, greeen, and blue, respectively. As part of the preprocessing step, color images in RGB format are converted to YCbCr space (for more information, see the section on Image Basics). The algorithm used for grayscale images is then applied to each of the Y, Cb, and Cr channels. Let's use the example of the image at right to illustrate the process.
The Color JPEG Process
We start with the three color channels shown below,
and convert them to YCbCr space:
We next substract 127 from all elements in each of the Y, Cb, and Cr channels and partition the results into 8 x 8 blocks. The DCT is applied to each block in each channel and then the quantization step follows on each block in each channel. We then apply Huffman coding to each of the quantized blocks in the three channels.
The Coding Step
For simplicity's sake, we apply regular Huffman coding (see the Section Image Compression in a Nutshell) to measure the effectiveness of the algorithm. Each of the original channels are 160 x 240 pixels so that the total number of bits needed to store the image is 160 rows * 240 columns * 3 channels * 8 bits per pixel = 921,600 bits. Using Huffman coding, we need 76,284 bits to store the elements in the Y channel, 48,775 bits to store the Cb channel, and 47,769 bits to store the Cr channel for a total of 172,828 bits or about 1.5bpp. This represents a savings of over 80% of the original space needed to store the image.
Inverting the Process
To invert the process, we use the same algorithm for inversion (described in Basic JPEG) to each of the compressed channels. In this way, we obtain modified versions of the Y, Cb, and Cr channels. These modified channels are then converted back to RGB space. We have plotted the original RGB matrices and the compressed RGB matrices below:
The two images below are the original image (at left) and the compressed image (at right).