ME 535 FINAL PROJECT Image Compression Techniques Mohammed Abdul Kareem, UWID: 1771823 Sai Krishna Madhavaram, UWID: 1725952 Palash Roychowdhury, UWID:1725115 Department of Mechanical Engineering University of Washington
Introduction: Image Compression Data compression algorithms are designed specifically for reducing the size of an Image are used for compressing images for a large segment of data exchanged. Thus, Image compression softwares aid in saving storage space and time of data transfer. By altering key parameters of the algorithm during the compression, we can generate suitable image quality and file size. There are two main types of image compression algorithms: Lossy and Lossless compression. Lossy compression losses some information due to the compression whereas lossless algorithms retain all the information of an image. It is commonly observed that Lossy algorithms tend to generate higher compression ratios in comparison with Lossless algorithms. This study deals with comparing the compression ratios and output image qualities of Discrete Cosine Transform (DCT) and Fast Fourier Transform (FFT). Both of these algorithms come under the Lossy compression techniques and have high compression ratios. Joint Photographics Expert Group (JPEG) is a commonly used Lossy Compression type algorithm, we are going to perform DCT and FFT techniques on JPEG images and compare them. We do this in 3 main steps. First, we divide the image into multiple pixel blocks. An 8x8 size of pixel blocks are used for simplicity. Then, we change the image from spatial domain to frequency domain. Next, we quantize the data from frequency domain to filter out all the information we can afford to lose. Once these steps are completed then we will decompress the image by reverting it back to spatial domain and the reduced size image is obtained. Let's study each step in detail.
Procedure: Step 1: We divide the image into 8x8 blocks of pixels starting from the top left corner. For some images the pixels are not very well divided so they may not be in multiples of 8. For such images we add extra pixels to the image and make it a multiple of 8 by means of padding. These extra pixels values that are added will be removed once we have completed the 3 steps. Since we are doing a grayscale image compression and not for the color images, we have only white and black as the available color. So, each byte of the image can have a value between 0 which is full black and 255 which is full white. For simplicity we change the value of the colors by 128 from each byte so as to make the average tending to zero, where -128 is full black and 127 is full white. Once this process is done we proceed to next step. Step 2: Once the image is divided and pixels are assigned values in 64 byte block, we now convert the pixel data from spatial domain to the frequency domain. This is done since the techniques we are using for compression are functions of frequency, it will be easy for us to do the quantization process and remove the the unnecessary information in order to save the storage size. The way we go about it is, since every byte in the block represents the intensity of each pixel and when this is converted to the frequency domain, each value will be a variation of cosine function either in amplitude or phase change. For different frequencies it has different values and the whole block is now represented by multiplying those amplitudes with their respective cosine function and adding them. Once the frequency data is obtained, we filter out all the high frequency data since human being vision has trouble detecting high frequency data points. And once the data is removed, there is some loss in picture quality but human eye
cannot differentiate between the newly obtained image and the original one. This filtering of data is called Quantisation. Now coming to the algorithms we are going to use to compress the image, the FFT was one of the few popular algorithms used back then. Although the issue with FFT is that there are many imaginary components which are obtained which cannot be processed in spatial domain. Hence, these days we use DCT which is derived from FFT itself and is much faster in compressing the image and provides good compression ratios. The DCT usually is used for 1D data and in this case we apply it in x-direction and y-direction separately, thereby forming a 2D DCT. The 2D Discrete Cosine Transform equation is given in below. p(x, y) is the 8-bit image value at coordinates (x, y), and D (i, j) is the new entry in the frequency matrix. For an 8x8 matrix, this becomes: We take i and j as per the 8x8 pixel matrix so as to get the transition from spatial domain to frequency domain. The frequency matrix has values from -1024 to 1023 with the first element being the lowest frequency cosine coefficient and as we move to the right the values keeps on increasing. They represents the functions with increasing frequencies. And if we go down vertically then as well the frequency increases. Thereby leading to the final element which have the highest value. The whole lower right part of the matrix
has high frequency values which will be factored out after quantisation. This way almost half the matrix data is removed. As we can from the image below. Step 3: Now in order to remove the high frequency data from the matrix, we divide each of the coefficients with a certain fixed constant and then we round it down to the closest integer value. This fixed constant value has been researched about and they came up with certain numbers which gives out the best possible outcome for the compressed image. These values are then collected in a 8x8 matrix for our image and is called Quantization matrix. This matrix will be symmetrical about the diagonal and as mentioned earlier the matrix will have high frequency values in lower right part of it and low frequency values in upper left part. An optimised example standard quantisation matrix is shown below. It gives out an image of quality level of 50.
The algorithm takes a value from the Frequency matrix (F) and divides it by its corresponding value in the Quantization matrix (Q). This gives the final value for the location in the Quantized Frequency matrix (F quantize ). Decompressing the transformed image: Now to change the transformed image from frequency domain to spatial domain we need to first multiply each value with its respective quantisation matrix element and then we need to use the Inverse DCT technique to obtain the actual image. Given below is the Equation for the IDCT: And then we need to undo the changes made to the byte of each element by adding 128 to them as we subtracted the same amount in order to make the average to zero. Also we need to remove the any extra pixels that were added to make the image pixel division a multiple of 8. And then the pixels are combined to form a compressed image.
Compression Ratio After the compressed image is obtained, the compression ratio is calculated. A compression ration gives us the comparison of how much the data was compressed for a particular compressed image quality. A higher compression ratio is desirable but it also results in more data loss. Therefore, a balance between the high compression ratio and less data loss needs to be done.
Results: Original Image DCT of Image From the above images we can see that too high of a compression would result in more data loss due to which an image can become unpleasant to look and one can notice the low quality of the image. DCT Coefficient Matrix
DCT Matrix Running the matlab code gave us the following result for the total time for computing all these (5) images: Elapsed time is 3.124373 seconds Compressed Images with no. of Coefficients used (out of 64 Coefficients ) Compression ratios ~(10 30 50 70 90 100)%
Signal to Noise Ratio(SNR) as a function of no. of coefficients (Quality of obtained image)
Image compression with FFT: We used DCT in the previous part for image compression. In this part we are using the Fast Fourier Transform (FFT) to compress the images. Different compression ratios are depicted in the plot as well. FFT of the original image
FFT of the Image Compressed Images Running the matlab code gave us the following result for the total time for computing all these images: Elapsed time is 7.295931 seconds
Conclusion: From the results we can see that the DCT performs better than the FFT as it is faster and produces better results. References: Image Compression, Comparison between Discrete Cosine Transform and Fast Fourier Transform and the problems associated with DCT, Imdad Ali Ismaili, Sander Ali Khowaja, Waseem Javed Soomro Brunton, Steve, Dr. FFT and Image Compression. ME 565 Mechanical Engineering Analysis. Web. 1 March 2018.