You are on page 1of 3

EXPERIMENT NO.

6
Objective: Write a program for image Compression using 2-D Discrete cosine transform. Software Used: MATLAB R2010a About the Experiment: The compression scheme we used was to set a threshold value that was some fraction of the norm of the entire wavelet transform matrix. If the magnitude of a wavelet in the representation was not larger than this value, it was not included in the compression. We then rebuilt an image which (to some degree that depended on how many bases we included) resembed the original image by running the inverse transform. Theory: 2-D Discrete cosine transform (DCT) The discrete cosine transform (DCT) is closely related to the discrete Fourier transform. It is a separable linear transformation; that is, the two-dimensional transform is equivalent to a one-dimensional DCT performed along a single dimension followed by a one-dimensional DCT in the other dimension. Inverse discrete cosine transform The inverse discrete cosine transform reconstructs a sequence from its discrete cosine transform (DCT) coefficients. The idct function is the inverse of the dct function. compression ratio= compressed/actual Syntax 1) B = dct2(A) returns the two-dimensional discrete cosine transform of A. The matrix B is the same size as A and contains the discrete cosine transform coefficients B(k1,k2). 2) B = idct2(A) returns the two-dimensional inverse discrete cosine transform (DCT) of A.

MATLAB Program: z=imread('C:\Users\Public\Pictures\Sample Pictures\Koala.jpg'); x=rgb2gray(z); subplot(2,2,1); imshow(z); y=imresize(x,[256,256]); a=double((y/256)); %double(x) returns the double-precision value for y c=dct2(a); % 2-D discrete cosine transform subplot(2,2,2) imshow(c); count=0; for i=1:256 for j=1:256 if abs(c(i,j))<=.07 c(i,j)=0; count=count+1; end end end p=idct2(c); subplot(2,2,3) imshow(a); title('original image'); subplot(2,2,4) imshow(p); title('compressed image'); whos;

Result:

Image Properties: Name a c count i j p x y z Size 256x256 256x256 1x1 1x1 1x1 256x256 384x512 256x256 384x512x3 Bytes Class Attributes

524288 double 524288 double 8 double 8 double 8 double 524288 double 196608 uint8 65536 uint8 589824 uint8

You might also like