7
Penn State Harrisburg Digital Image Processing Image Compression using DCT Chad Ryan Weiss 4/25/2016

Project004

Embed Size (px)

Citation preview

Page 1: Project004

Penn State Harrisburg

Digital Image Processing

Image Compression using DCT

Chad Ryan Weiss4/25/2016

Page 2: Project004

Abstract:

Image compression has become the most important, energy efficiency method for transferring videos and images via any communication system. Before some of the very first image compression techniques were ever established, it would take hours to upload, download, file share and transmit media files because the file sizes were too big. Even with the 4G technology that we have today, these tremendous file sizes would still pose a major problem to memory storage systems. Since the dawn of the early digital image processing days, scientists and mathematicians have been coming up with clever ways to compress images and frames for easy storage and data transfer. Methods like the discrete cosine transform use highly advanced mathematical principles to represent images that allow for modification and clever size manipulation of the overall image. By implementing digital image processing techniques like the discrete cosine transform, one would essentially make the packet of information a lot lighter for transport and storage.

Page 3: Project004

Theory:

The discrete cosine transform (DCT) is a method that represents an image as a sum of sinusoids of varying magnitudes and frequencies. It is this representation of the image as a sum of sinusoids that allows for the fact that most of the visually significant information about the image is concentrated in the DCT coefficients. For this reason, DCT has become a well-known, popular image compression standard for lossy image compression. An important quality about the DCT is that it is invertible, which is convenient for the realm of image compression because it is sometimes necessary and recover the original image for the sake of acquiring the primary source of information.

When compressing an image using DCT, the image input is first divided into 8 by 8 or 16 by 16 blocks and then the DCT is computed for each block of information. The coefficients of the DCT transform are then obtained, quantized, coded and transmitted. Once the transmitter has essentially transferred all of the information and the receiver has picked up the signal, the receiver begins to decode the quantized coefficients, computes the inverse DCT of each block and then reconstructs the original image.

The reason the DCT is called a lossy method for compressing images is due to the fact that many of these coefficients are nearly zero and hold not-so-important information in regards to the big picture. These values are simple thrown out because they can be and the image becomes smaller. Usually, the user has no idea that these have been thrown out because of how small or insignificant these parts of the image were to the overall whole.

Example Code:

clear all; close all; clc;

I = imread('NASA.jpg');

I=double(I(:,:,1))/255;

T = dctmtx(8);

B = blkproc(I,[8 8],'P1*x*P2',T,T');

mask = [1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];

B2 = blkproc(B,[8 8],'P1.*x',mask);

I2 = blkproc(B2,[8 8],'P1*x*P2',T',T);

imtool(I);

imtool(I2);

The code seen at left will compress a two-dimensional image using the DCT. We start by reading in an image using the imread function. Following this immediate action we then convert the image to data type double and scale it down to account for this data shift. Next, we create a DCT coefficient matrix using the dctmtx function, which will be used in the preceding lines of code to pre and post multiply the 8-by-8 blocks of data of our image. The blkproc function creates the 8-by-8 chunks of data and allows us to throw in the pre and post multiplication as part of the function’s input arguments. Finally we decide which coefficients to keep by applying the mask and then applying the inverse DCT to recover the image and display the outputs. (NEXT)

Page 4: Project004

Figure 1 represents the original image. After saving this image to the desktop, the size of this original file was found to contain 33.8 kb of data. Now we will determine the compression ratio of this particular example by referring to the next image.

Figure 1: Original Image

Page 5: Project004

Figure 2 represents the compressed image. It can be seen that some of the finer details have been blurred or left out entirely. After saving this file to the desktop, the file size was found to be only 13 kb!

The DCT yielded a compression ratio of about C = 33.8 kb / 13 kb = 2.6!

Page 6: Project004

Conclusion:

In summary, we talked about how the DCT is used in digital image processing as well as the implications of image compression. We briefly talked about some of the theory behind the DCT and found that a lot of it is based on highly advanced mathematical and scientific concepts. Lastly, we provided an example of the DCT image compression techniques sing MatLab. The results were displayed and we found for our particular example that the output image was compressed by a factor of 2.6 without any major loss of information as to what the big picture actual represents.