PROJECT dct

68

Transcript of PROJECT dct

Page 1: PROJECT dct
Page 2: PROJECT dct
Page 3: PROJECT dct
Page 4: PROJECT dct
Page 5: PROJECT dct
Page 6: PROJECT dct
Page 7: PROJECT dct
Page 8: PROJECT dct
Page 9: PROJECT dct
Page 10: PROJECT dct
Page 11: PROJECT dct
Page 12: PROJECT dct
Page 13: PROJECT dct
Page 14: PROJECT dct
Page 15: PROJECT dct
Page 16: PROJECT dct
Page 17: PROJECT dct
Page 18: PROJECT dct
Page 19: PROJECT dct
Page 20: PROJECT dct
Page 21: PROJECT dct
Page 22: PROJECT dct
Page 23: PROJECT dct
Page 24: PROJECT dct
Page 25: PROJECT dct
Page 26: PROJECT dct
Page 27: PROJECT dct
Page 28: PROJECT dct
Page 29: PROJECT dct
Page 30: PROJECT dct
Page 31: PROJECT dct

PROJECT: IMAGE COMPRESSION USING DISCRETE COSINE TRANFORM IMPLEMENTING MATLAB

PROPERTIES OF DCT: Some properties of the DCT which are of particular value to image processing applications: a) Decorrelation: The principle advantage of image transformation is the removal of redundancy between neighboring pixels. This leads to uncorrelated transform coefficients which can be encoded independently. It can be inferred that DCT exhibits excellent decorrelation properties. b) Energy Compaction: Efficacy of a transformation scheme can be directly gauged

by its ability to pack input data into as few coefficients as possible. This allows the quantizer to discard coefficients with relatively small amplitudes without introducing visual distortion in the reconstructed image. DCT exhibits excellent energy compaction for highly correlated images. c) Separability: The DCT transform equation can be expressed as

This property, known as separability, has the principle advantage that D (i, j) can be computed in two steps by successive 1-D operations on rows and columns of an image. The arguments presented can be identically applied for the inverse DCT computation. d) Symmetry: Another look at the row and column operations in above Equation reveals that these operations are functionally identical. Such a transformation is called a symmetric transformation. A separable and symmetric transform can be expressed in the formD = TMT’ where M is an N ×N symmetric transformation matrix This is an extremely useful property since it implies that the transformation matrix can be precomputed offline and then applied to the image thereby providing orders

PROJECT: IMAGE COMPRESSION USING DISCRETE COSINE TRANFORM IMPLEMENTING MATLAB )

of magnitude improvement in computation efficiency.

COMPARISON OF MATRICES: Let us now see how the JPEG version of our original pixel block compares,

CONCLUSION:

Page 32: PROJECT dct

If we look at the above two matrices, this is a remarkable result, considering that nearly 70% of the DCT coefficients were discarded prior to image block decompression/reconstruction. Given that similar results will occur with the rest of the

MATLAB CODE: PROJECT: IMAGE COMPRESSION USING DISCRETE COSINE TRANFORM IMPLEMENTING MATLAB )

blocks that constitute the entire image, it should be no surprise that the JPEG image will be scarcely distinguishable from the original. Remember, there are 256 possible shades of gray in a black-and-white picture, and a difference of, say, 10, is barely noticeable to the human eye. DCT takes advantage of redundancies in the data by grouping pixels with similar frequencies together. And moreover if we observe as the resolution of the image is very high, even after sufficient compression and decompression there is very less change in the original and decompressed image. Thus, we can also conclude that at the same compression ratio the difference between original and decompressed image goes on decreasing as there is increase in image resolution. >>o = imread ('e:\img10.jpg'); w = size (o, 2); samplesHalf = floor(w / 2); samplesQuarter = floor(w / 4);samplesEighth = floor(w / 8);ci2 = [];ci4 = [];ci8 = [];fork=1:3% all color layers: RGB for i=1:size(o, 1)% all rows rowDCT = dct(double(o(i,:,k)));ci2(i,:,k) = idct(rowDCT(1:samplesHalf), w);ci4(i,:,k) = idct(rowDCT(1:samplesQuarter), w);ci8(i,:,k) = idct(rowDCT(1:samplesEighth), w);end end h = size(o, 1);samplesHalf = floor(h / 2);samplesQuarter = floor(h / 4);samplesEighth = floor(h / 8);ci2f = [];ci4f = [];ci8f = [];

Page 33: PROJECT dct

fork=1:3% all color layers: RGB for i=1:size(o, 2)% all columns

PROJECT: IMAGE COMPRESSION USING DISCRETE COSINE TRANFORM IMPLEMENTING MATLAB )

columnDCT2=dct(double(ci2(:,i,k)));columnDCT4=dct(double(ci4(:,i,k)));columnDCT8=dct(double(ci8(:,i,k)));ci2f(:,i,k) = idct(columnDCT2(1:samplesHalf), h);ci4f(:,i,k) = idct(columnDCT4(1:samplesQuarter), h);ci8f(:,i,k) = idct(columnDCT8(1:samplesEighth), h);end end subplot(2,2,1), image(uint8(o)), title('Original Image');subplot(2,2,2), image(uint8(ci2)), title('Compression Factor 2');subplot(2,2,3), image(uint8(ci4)), title('Compression Factor 4');subplot(2,2,4), image(uint8(ci8)), title('Compression Factor 8');figuresubplot(2,2,1), image(uint8(o)), title('Original Image');subplot(2,2,2), image(uint8(ci2f)), title('Compression Factor 2 * 2');subplot(2,2,3), image(uint8(ci4f)), title('Compression Factor 4 * 4');subplot(2,2,4), image(uint8(ci8f)), title('Compression Factor 8 * 8');

THE OUTPUT IMAGES: 1) Image of size 352 × 352:

Page 34: PROJECT dct
Page 35: PROJECT dct
Page 36: PROJECT dct
Page 37: PROJECT dct

PROJECT: IMAGE COMPRESSION USING DISCRETE COSINE TRANFORM IMPLEMENTING MATLAB )

a) DCT to rows only:

Original Image 100 200

Page 38: PROJECT dct

300

100 200 300 Compression Factor 2 100 200 300

100 200 300 Compression Factor 4 100 200 300

100 200 300 Compression Factor 8 100 200 300

100 200 300

Page 39: PROJECT dct
Page 40: PROJECT dct
Page 41: PROJECT dct
Page 42: PROJECT dct
Page 43: PROJECT dct

PROJECT: IMAGE COMPRESSION USING DISCRETE COSINE TRANFORM IMPLEMENTING MATLAB )

b) DCT to rows*column:

Original Image 100

Page 44: PROJECT dct

200 300

100 200 300 Compression Factor 2 * 2 100 200 300

100 200 300 Compression Factor 4 * 4 100 200 300

100 200 300 Compression Factor 8 * 8 100 200 300

100 200 300

In today’s technological world as our use of and reliance on computers continues to grow, so too does our need for efficient ways of storing large amounts of data and due to the bandwidth and storage limitations, images must be compressed before transmission and storage.For example, someone with a web page or online catalog that uses dozens or perhaps hundreds of images will more than likely need to use some form of image compression to store those images. This is because the amount of space required to hold unadulterated images can be prohibitively large in terms of cost. Fortunately, there are several methods of image compression available today. This fall into two general categories: lossless and lossy image compression.

Page 45: PROJECT dct

However, the compression will reduce the image fidelity, especially when the images are compressed at lower bit rates. The reconstructed images suffer from blocking artifacts and the image quality will be severely degraded under the circumstance of high compression ratios. In order to have a good compression ratio without losing too much of information when the image is decompressed we use DCT.

A discrete cosine transform(DCT) expresses a sequence of finitely many data points in terms of a sum of cosine functions oscillating at different frequencies. The JPEG process is a widely used form of lossy image compression that centers on the Discrete Cosine Transform. DCT and Fourier transforms convert images from time-domain to frequency- domain to decorrelate pixels. The DCT transformation is reversible .The DCT works by separating images into parts of differing frequencies. During a step called quantization, where part of compression actually occurs, the less important frequencies are discarded, hence the use of the term “lossy“. Then, only the most important frequencies that remain are used retrieve the image in the decompression process. As a result, reconstructed images contain some distortion; but as we shall soon see, these levels of distortion can be

adjusted during the compression stage. The JPEG method is used for both color and black- and-white images.

THE JPEG PROCESS: The following is a general overview of the JPEG process. JPEG stands for

Joint Photographic Experts Group which is a commonly used method of compression for photographic images. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in image quality. More comprehensive understanding of the process may be acquired as such given under:

1. The image is broken into 8x8 blocks of pixels. 2. Working from left to right, top to bottom, the DCT is applied to each block. 3. Each block is compressed through quantization. 4. The array of compressed blocks that constitute the image is stored in a drastically reduced amount of space. 5. When desired, the image is reconstructed through decompression, a process that uses the Inverse Discrete Cosine Transform (IDCT).

THE DISCRETE COSINE TRANSFORM: Like other transforms, the Discrete Cosine Transform (DCT) attempts to

decorrelate the image data. After decorrelation each transform coefficient can be

Page 46: PROJECT dct

encoded independently without losing compression efficiency. This section describes the DCT and some of its important properties. 1) The One-Dimensional DCT: The most common DCT definition of a 1-D sequence of length N is

For u = 0, 1, 2, …, N −1

Similarly, the inverse transformation is defined as

For x = 0, 1, 2, …, N −1. In both equations as above,α (u) is defined as

It is clear from first equation that for

Thus, the first transform coefficient is the average value of the sample sequence. In literature, this value is referred to as the DC Coefficient. All other transform coefficients are called the AC Coefficients2) The Two-Dimensional DCT:

The Discrete Cosine Transform (DCT) is one of many transforms that takes its input and transforms it into a linear combination of weighted basis

Page 47: PROJECT dct

functions. These basis functions are commonly the frequency. The 2-D Discrete Cosine Transform is just a one dimensional DCT applied twice, once in the x direction, and again in the y direction. One can imagine the computational complexity of doing so for a large image. Thus, many algorithms, such as the Fast Fourier Transform (FFT), have been created to speed the computation. The DCT equation (Eq.1) computes the i, jth entry of the DCT of an image

p (x, y) is the x,yth element of the image represented by the matrix p. N is the size of the block that the DCT is done on. The equation calculates one entry (i, j th) of the transformed image from the pixel values of the original image matrix. For the standard 8x8 block that JPEG compression uses, N equals 8 and x and y range from 0 to 7. Therefore D (i, j ) would be as in Equation (3).

Because the DCT uses cosine functions, the resulting matrix depends on the horizontal and vertical frequencies. Therefore an image black with a lot of change in frequency has a very random looking resulting matrix, while an image matrix of just one color, has a resulting matrix

of a large value for the first element and zeroes for the other elements.

THE DCT MATRIX: To get the matrix form of Equation (1), we will use the following equation

Page 48: PROJECT dct

For an 8x8 block it results in this matrix:

Page 49: PROJECT dct
Page 50: PROJECT dct
Page 51: PROJECT dct
Page 52: PROJECT dct
Page 53: PROJECT dct
Page 54: PROJECT dct
Page 55: PROJECT dct
Page 56: PROJECT dct
Page 57: PROJECT dct
Page 58: PROJECT dct
Page 59: PROJECT dct
Page 60: PROJECT dct
Page 61: PROJECT dct
Page 62: PROJECT dct
Page 63: PROJECT dct
Page 64: PROJECT dct
Page 65: PROJECT dct
Page 66: PROJECT dct