12-06-2012, 02:54 PM
JPEG Image Compression Implemented in Matlab
JPEG Image Compression.doc (Size: 34 KB / Downloads: 523)
Abstract:
In this project I attempted to implement basic JPEG compression using only basic Matlab functions. This included going from a basic grayscale bitmap image all the way to a fully encoded file readable by standard image readers. I will show that I have implemented the majority of the project, including much of the final binary coding. Although I never obtained a fully completed image from my functions, I came very close.
Results:
In this section I will present the steps of obtaining a finalized JPEG file and how I implemented each step in matlab. I will comment on possible improvements and mistakes made in each case. The code used is attached at the end of this report.
Step1: Converting the base image to 8x8 matrices, DCT transform, quantizing
These steps were relatively easy, especially in matlab, which is specifically set up to work with matrices. The 2-D discrete cosine transform is done simply with the dct2() command. After splitting the matrix into 8x8 matrices and performing the DCT, a simple piecewise division by the quantization matrix obtains the quantized matrices needed for the next step.
Step 2: Zig-Zag Encoding of Quantized Matrices
I found no matlab implementation for this function, so I wrote one myself. I took advantage of the fact that each diagonal row has addresses that add up to the same number. Depending on whether the number is even or odd determined the direction of the iteration through the row. The code I wrote is able to zig-zag through any matrix of equal height and width. This could be useful if one wanted to experiment with deviding images into matrices larger than 8x8.
Conclusion:
While not completing the goal I set out to achieve, I have demonstrated that conversion from a grayscale image to the JPEG encoded binary bit stream is a fairly simple and straightforward process. It comes as no surprise to me that the file I/O was the most challenging part of the process.