Professional Documents
Culture Documents
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:
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 = [];
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');
figure
subplot(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:
PROJECT:
IMAGE COMPRESSION USING DISCRETE COSINE TRANFORM IMPLEMENTING MATLAB
)
a) DCT to rows only:
Original Image
100
200
300
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
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
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
Coefficients
2) 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
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.