In this project, we examined how to compress image and audio files using different compression methods. For images, we used linear quantization, JPEG-matrix compression and JPEG quantization.
For linear quantization, we first convert our image into doubles for calculations and then split them into a series of smaller 8 by 8 matrices. For colored images, this process is done for each seperate color layer (R,G,B),while a black and white image is simply converted as a whole. We then subtract 128 from each value, which moves the range of our color values from 0 - 256 to -128 - 128. Doing so centers the numbers around 0, which helps reduce some of the data loss that results from the compression. We now perform a least squares approximation of our subsets using the 2D-DCT, which is an interpolation theorem defined by: \[ C_{ij} = \frac{\sqrt{2}}{\sqrt{n}} a_i cos \frac{i(2j+1)\pi}{2n} \] The resulting orthogonal matrix C can then be multiplied by our 8x8 subset and its own inverse to interpolate the data in our subset. By interpolating the data, we set our subsets up for a least squares fit in our next step. We will later undo the interpolation to retrieve the original data. At this point we bring in an 8x8 matrix called the quantization matrix, which will regulate how each pixel in our 8x8 subsets is transformed and will be used for a least squares fit. For linear quantization, this matrix is given by the formula:
where p is called the loss parameter. The higher the value used for p is, the more compressed the image becomes and the more data is lost as a result. By dividing each value in our 8x8 subsets by the respective value in Q and rounding, we reduce the amount of information stored in the subsets. Multiplying value by Q again returns the rounded versions of our values. Afterwards, we undo the earlier 2D-DCT by multiplying the transpose C matrix by our 8x8 subset and then by the original C matrix. Lastly, we add back the 128 to our values to bring them back to the original range and convert them back to unsigned 8-bit integers for plotting.
The simple JPEG compression is the same as linear quantization, except that the quantization matrix Q is different. The suggested matrix used for JPEG compression is:
Like linear quantization, most of the steps for JPEG-Quantization are the same. However, JPEG-Quantization does not use RGB like the previous two methods. Instead we convert our RGB color data to the YUV system with: