University of Maryland College Park Digital Signal Processing: ENEE425 Fall 2012 Project#2: Image Compression Ronak Shah & Franklin L Nouketcha
I- Introduction Data compression is core in communication as it diminishes the size of files, and therefore facilitates their transmission. In this project we are compressing the images of Lena (Fig.1) and Baboon (Fig.2) respectively subject to a PSNR of 40 and 20. The PSNR indicates the quality of the image, and the compression ratio is the ratio in size of the compressed image and its original. Better compressions are achieved with large compression ratios; however, as the compression ratio increases, the PSNR decreases degrading the overall quality of the image. The problem is resumed to one question. How can we achieve a large compression ratio without destroying the quality of the image? Figure 1: original picture of Lena
Figure 2: Original Picture of baboon II- Approach Compressing an image is to represent the most important components of that image with more bits while allocating fewer bits to its less important components. One way to look at the most important components of a picture is to look at its DCT spectrum obtained by performing a two dimensional discrete cosine transform (2-D DCT). In this project we performed the DCT on each 8X8, 16X16 and 32X32 blocks of the original images, and by carefully analyzing the resulting DCT spectrums, we made the appropriate quantization table to compress the images. For the case where the image was divided into 8X8 blocks for instance, there were a total of 4096 blocks of such size as the original image had 262144 blocks (512X512).
The quantization table needed in this case is supposed to be 8X8 and made in a way that it would fairly quantize all of the 4096 blocks not just a specific block. We look at all the 4096 blocks at the same time and we took the variance of all the elements having the same position within each block, to obtain a total of 64 variances that we redistributed in a 8X8 table (Fig.3). Figure 3: Example of variance table (Baboon 8X8 blocks) The variance matrix shows the most important positions within a block that need to be represented with more bits and the less important positions within a block to be represented with fewer bits (even zero). Higher variances correspond to important positions, thereby needing more bits. To have better and fair allocation of the quantization table we defined some threshold values (Fig.4) in order to compare the range of all the variances. The most important blocks were to be assigned eight bits and denoted by 1= (2 0 ) in the quantization table (division by 2 n in binary shift to the right n times resulting in n less bits). The second less important blocks were to be assigned 7 or fewer bits (division by 2 resulting in seven bits) as depicted in Fig.5. And so on. In order to obtain a higher compression ratio we just adjusted our threshold values to achieve a quantization table that would get rid of more bits.
Figure 4: Threshold value use to make Variance table of baboon to obtain PSNR =40 Figure 5: An example of a quantization table for baboon 8X8 subject to PSNR=40. Once the DCT of the original image was quantized we found the inverse discrete cosine transform (IDCT) for each block to reconstruct the compressed image. We followed the same step for the 16X16 blocks (1024 blocks totals) and for the 32 by 32 blocks (256 blocks total). A- 8X8 blocks III- Lena For this case we subjected to a PSNR of 39.95 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 8 Greater than 300 7 150-300 6 50-150 5 40-50 4 20-40 0 Less than 20
It had a compression ratio of 2.752. Below (Fig. 6) is the resulting image produced after such compression: Figure 6: Reconstructed image of Lena for 8X8 PSNR=40. For this next case we subjected to a PSNR of 26.26 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 1 90000-100000 0 Less than 90000
It had a compression ratio of 512 as a lot of the data is lost. Below (Fig. 7) is the resulting image produced after such compression: B- 16X16 blocks Figure 7: Reconstructed image of Lena for 8X8 PSNR~20. For this case we subjected to a PSNR of 40.51 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 8 Greater than 300 7 100-300 6 50-100 5 30-50 4 15-30 0 Less than 15
It had a compression ratio of 2.663. Below (Fig. 8) is the resulting image produced after such compression: Figure 8: Reconstructed image of Lena for 16X16 PSNR=40. For this next case we subjected to a PSNR of 26.36 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 1 300000-1000000 0 Less than 300000 It had a compression ratio of 2048 as a lot of the data is lost. Below (Fig. 9) is the resulting image produced after such compression:
C- 32X32 blocks Figure 9: Reconstructed image of Lena for 16X16 PSNR~20. For this case we subjected to a PSNR of 40.01 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 8 Greater than 390 7 225-390 6 115-225 5 50-115 4 10-50 0 Less than 10 It had a compression ratio of 2.597. Below (Fig. 10) is the resulting image produced after such compression:
Figure 10: Reconstructed image of Lena for 32X32 PSNR=40. For this next case we subjected to a PSNR of 26.14 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 1 1000000-10000000 0 Less than 1000000 It had a compression ratio of 8192 as a lot of the data is lost. Below (Fig. 11) is the resulting image produced after such compression:
Figure 11: Reconstructed image of Lena for 32X32 PSNR~20.
A- 8X8 blocks IV- Baboon For this case we subjected to a PSNR of 40.19 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 8 Greater than 400 7 250-400 6 150-250 5 100-150 4 50-100 0 Less than 50 It had a compression ratio of 1.31 as a lot of the data is lost. Below (Fig. 12) is the resulting image produced after such compression: Figure 12: Reconstructed image of Baboon 8X8 subject to PSNR=40.
For this next case we subjected to a PSNR of 21.55 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 8 Greater than 1000000 7 500000-1000000 6 450000-500000 5 45000-450000 4 40000-45000 0 Less than 40000 It had a compression ratio of 102.4 as a lot of the data is lost. Below (Fig. 13) is the resulting image produced after such compression: Figure 13: Reconstructed image of Baboon 8X8 subject to PSNR~20.
B- 16X16 blocks For this case we subjected to a PSNR of 40.08 with the following bit assignment for quantization levels for various variance ranges: Bits Allocated Variance Range 8 Greater than 1000 7 500-1000 6 200-500 5 100-200 4 50-100 0 Less than 50 It had a compression ratio of 1.43 as a lot of the data is lost. Below (Fig. 14) is the resulting image produced after such compression: Figure 14: Reconstructed image of Baboon 16X16 subject to PSNR=40 For this next case we subjected to a PSNR of 21.29 with the following bit assignment for quantization levels for various variance ranges:
Bits Allocated Variance Range 8 Greater than 100000 7 65000-100000 6 50000-65000 5 25000-50000 4 20000-25000 0 Less than 20000 It had a compression ratio of 256 as a lot of the data is lost. Below (Fig. 15) is the resulting image produced after such compression: Figure 15: Reconstructed image of Baboon 16X16 subject to PSNR~20. C- 32X32 blocks For this case we subjected to a PSNR of 39.38 with the following bit assignment for quantization levels for various variance ranges:
Bits Allocated Variance Range 8 Greater than 500 7 250-500 6 200-250 5 100-200 4 50-100 0 Less than 50 It had a compression ratio of 1.39 as a lot of the data is lost. Below (Fig. 16) is the resulting image produced after such compression: Figure 16: Reconstructed image of Baboon 32X32 subject to PSNR=40. For this next case we subjected to a PSNR of 21.57 with the following bit assignment for quantization levels for various variance ranges:
Bits Allocated Variance Range 8 Greater than 500000 7 250000-500000 6 100000-250000 5 50000-100000 4 10000-50000 0 Less than 10000 It had a compression ratio of 199.81 as a lot of the data is lost. Below (Fig. 17) is the resulting image produced after such compression: Figure 17: Reconstructed image of Baboon 32X32 subject to PSNR~20.
V- Conclusion The table below summarizes our results that we obtained. Lena Baboon 8x8 16x16 32x32 PSNR Compression Ratio PSNR Compression Ratio PSNR Compression Ratio 39.95 2.752 40.51 2.6632 40.01 2.597 26.26 512 26.36 2048 26.14 8192 40.186 1.313 40.08 1.431 39.39 1.397 21.545 102.4 21.29 256 21.58 199.805 Our results are what we expected to obtain. We achieved good compression ratios for both figures subject to a PSNR of 40. Lena was able to be compressed more than Baboon. This is due to the way Baboon is compromised. Baboon has a lot of high frequency components. Therefore, Baboon has a lot of its data stored in the top left corner coefficients of a N*N block which leaves very little data in the lower right corner coefficients to be truncated. Therefore, you will not achieve a compression rate as high as Lena. While Lena, had a majority of its data stored in coefficients in the top left corner, it had more coefficients in the lower right corner than Baboon that could be truncated to achieve a quality with PSNR of 40; thereby having a higher compression ratio. The images lost a lot of quality when subject to a PSNR of 20, as expected. Therefore, compression ratios were very high as a lot of data had to be truncated to zero in order to achieve such a PSNR, including coefficients in the very top left corner. However, this is expected for an image being compressed subject to such a PSNR of 20. A large difficulty of the project is determining how to develop your quantization matrix that you will apply to each DCT N*N block based off the variances. Initially we had decided to go with a quantization matrix that would be compromised of zeros and ones that would then be multiplied to each N*N block. Determining where the ones and zeros would be placed, was based on an analysis of variance values. Positions with higher variances would be multiplied by a one to preserve its
corresponding coefficient and positions with lower variances would be multiplied by a zero to throw out its corresponding coefficient. Therefore, positions that were multiplied by one would need 8 bits to be represented and 0 bits for positions that were multiplied by a zero. However, we found that this method was too drastic and resulted in compression ratios that were not satisfactory. The method we implemented alleviated this issue because it allowed for finer quantization levels rather than such drastic levels (8 bits or 0 bits). The difficulty in this method is that you must develop threshold ranges for variances and based off these ranges, assign a proper amount of bits to represent that coefficient. Determining these ranges to achieve the proper PSNR and the best compression ratio proved to be a difficult process. However, after many attempts, our final results are the best combination. A key lesson in this project was determining which block size proved to be the best in terms of the best compression ratio subject to a specific PSNR. We learned from our results that the best results are obtained through 8X8 and 16X16. The finer the segmentation, the smaller the variance in a particular position in an N*N block. Taking an extreme case, if we break the image into 64X64 blocks, a single block would cover a larger part of the image, thereby allowing for a larger variance between blocks as each block assumes a larger part of the image. Therefore, we found that the finer the segmentation, 8X8, the higher the compression ratio you can achieve subject to a PSNR. However, in order to achieve this result, one must be careful in determining their quantization levels. As more than one set of quantization levels can result in the same PSNR, thereby giving various compression ratios, one could get results that show a 32X32 segmentation providing a better compression ratio. Therefore, one must optimize their quantization levels to achieve the highest compression ratio when subject to a PSNR.