Study Of Multimedia Data Compression Methods Engineering Essay

In this report, there are 2 experiment which are about ‘Audio Compression Using Down sampling and Quantization’ and ‘Image Compression Using JPEG’The aim of the experiment is understand how audio compression and image compression is done using different method and which is more effective. A few of the major findings are, for the audio compression, sampling and quantization determines the quality of the compressed audio.For image compression, DCT and quantization determines the compression ratio and image quality.

Keywords

INTRODUCTION

AUDIO COMPRESSION USING DOWN-SAMPLING AND QUANTIZATION

2.1 Experiment 1: Effect of sampling rate and quantization resolution on sound quality

For multimedia data, it has high redundancy with result in very large file size. A set of discreet sound samples compose an audio date. Quantization and representation by binary code is done to each sound sample obtain. In this experiment, the principles of sampling continuous time signal, increasing or decreasing the sampling rate of a discrete time signal and change the quantization resolution are being explored. Speeches and music audio are recorded with various sampling rates and bits per sample, sampling rate conversion and quantization on digital signals are applied. Each of the sound quality obtained by different filters and quantizers are compared and each of them are observed.

2.1.1 Experiment Procedure

Part 1) Investigate the effect of sampling rate and bits per sample on sound quality

1) Different sampling frequencies and bit rate of audio recording.

a. Windows Media Player on the computer is started.

b. The recording control is configured to change the source of sound input.

The volume control panel is opened. (double-click the “speaker” icon in system tray), select “options-

properties->recording”, then select “CD Audio, Microphone, Stereo Mix” to all these three items in

recording control panel, as shown in Fig. 1, and click “OK”.

In recording panel below(Fig. 2), “Stereo Mix” is select d so the internal sound of the computer can be recorded

The sound recorder is opened (accessory -> entertainment -> sound recorder). The recorder properties are adjusted to set the sampling rate be 11.025 KHz, 8 bits/sample by selecting “file->properties->convert now”( Fig. 4). “PCM” is chosen for “format”, “11.025 KHz, 8 bits, mono” is chosen for “attributes”, type “.wav” for “save as”.

The “record” button is push and 30 seconds of the played audio is record. A file is used to save it using the “.wav” format.

The same audio segment is recorded using different sample rates and bits/sample and the sound quality is compared. The following is how audio quality can be subjectively evaluated:

No

Perceptual Quality

Comment

1

Poor

The sound is corrupted by excessive noise and the sound is no longer understandable

2

Acceptable

The sound is corrupted by moderate noise level

3

Good

The sound quality is perceived to be similar to the original sound

the procedure above for the following recording parameter are repeated and the perceptual quality is commented.

Sampling rate = 11.025 KHz

Music

8 bits/sample

Acceptable

Music

16 bits/sample

Good

Speech

8 bits/sample

Acceptable

Speech

16 bits/sample

Good

Sampling rate = 44.1 KHz

Music

8 bits/sample

Acceptable

Music

16 bits/sample

Good

Speech

8 bits/sample

Acceptable

Speech

16 bits/sample

Good

Here, we can see that the more bits per sample , the better quality is obtain and with the higher sampling rate, the better quality of audio is sampled.

The two programs on a sound file you have recorded earlier can be apply using a sampling frequency of 44KHz sampling frequency, 16 bits/sample.

MATLAB program is started. Directory is changed to your own working directory. All the program files and sample audio files are copied to your directory.

The “down4up4_nofilt” program is used on a sound file recorded with sampling frequency of 44KHz. Type For example : down4up4_nofilt(‘myinput.wav’,’myoutput.wav’)on the command window of MATLAB.

The mean square error is computed by the program between the original and the interpolated signal. The original sound and the one after down-sampling and upsampling are compare the in terms of perceptual sound quality, waveform, frequency spectrum and mean square error. ? The result are tabulated and analyze the result

Repeat the steps from part b. but use “down4up4_filt” instead. The results are tabulated and analyzed.

Without filter

withfilter

MUSIC

Down-sampling/Up-sampling

(No filter used)

Down-sampling/Up-sampling (With filter)

Mean square error

0.000638157

0.000130789

Perceptual Quality

Acceptable

Good

Comment on waveforms

Discrete,The levels are very high

Discrete,The levels are lower

Comment on frequency spectrum

The spectrum is oscillating in a decreasing manner and rise up at the end

The spectrum is oscillating in a decreasing manner

With the fliter, the quality is better due to it reducing the noise effect, thus reducing the mean square error.

Two MATLAB programsare given, quant_uniform.m and quant_mulaw.m. an input sequence using a uniform quantizer with a user-specified number of levels are quantized by the “quant uniform” . The mu- law quantizer is the “quant_mulaw” program to quantize it.

“quant_uniform” function is applied to a sound file recorded with 16 bits/sample to quantize it to a lower quantization levels. As an example to use 256 quantization levels (8 bits per sample) use N=256. Type (example)

quant_uniform(‘myinput.wav’,’myoutput.wav’,256) on the command window of MATLAB.

The original sequence and quantized sequences are compared with different quantization levels ( in terms of perceptual sound quality and the waveform). The quantization error (mean square error between the original and quantized samples) are recorded and compared. determine the minimum ‘N’ to which has a good sound quality.

“quant_mulaw” function is applied to a sound file recorded with 16 bits/sample, with mu=16.

The experiment is repeated for both music and speech audio data. Different quantization levels N are used. determine the minimum N to obtain an acceptable sound quality. Tabulate the result.

N is quantization level

N = 2b

b = number of bits used per level

Uniform quantization

Mu-Law quantization

Mu = 16

Mean square error (mse)

Perceptual quality

poor/acceptable

/good

Mean square error (mse)

N= 212

= 4096

1.17327X108

Good

1.36375X109

N= 210

= 1024

1.8777 X107

Good

2.30712X108

N= 28

= 256

2.95153X106

Acceptable

3.66273X107

N= 26

= 64

5.27229X105

Poor

5.52074X106

N= 24

= 16

0.00112348

Poor

9.02207X105

Uniform quantization(min acceptable) = N= 28

Mu-Law quantization(min acceptable) = N= 26

N is quantization levels

N = 2b

b = number of bits used per level

Uniform quantization

Mu-Law quantization

Mu = 16

Mean square error (mse)

Perceptual quality

poor/acceptable

/good

Mean square error (mse)

N= 212

= 4096

1.15236X108

Good

3.15122X109

N= 210

= 1024

1.84788X107

Acceptable

5.02324X108

N= 28

= 256

2.92896X106

Poor

8.06364X107

N= 26

= 64

4.744 X105

Poor

1.28916X105

N= 24

= 16

0.000769637

Poor

0.000207797

Uniform quantization(min acceptable) = N= 210

Mu-Law quantization(min acceptable) = N= 28

N=16

N=64

N=256

N=1024

N=4096

Mul

N=16

N=64

N=256

N=1024

N=4096

SpeechUni

N=16

N=64

N=256

N=1024

N=4096

MulSpeech

N=16

N=64

N=256

N=1024

N=4096

Here , we can see that the high quantization level, N. the better the sound quality and the error is smaller.

However the Mu-Law quantization is better than the uniform quantization, as the it has smaller distance between two levels at the lower frequency as our ears are more sensitive to lower frequency.

Conclusion is, as seen the experiments above, the higher sampling rate and bits per sample and with filter and using Mu-law quantization give a batter sound quality.

Investigate the effectiveness of JPEG scheme for compressing photographic image

Represent compressed image in frequency domain using DCT transform

Investigate the importance of different DCT coefficients

Investigate the tradeoff in the selection and quantization of DCT coefficients and its effect on compression ratio and image quality.

Discrete Cosine Transform (DCT) is the center of most popular lossy image compression standard. the JPEG compression standard on the internet. how to transform an image into a series of 8 x 8 DCT coefficients blocks, how to quantize the DCT coefficients and then how to reconstruct the image based on the quantized DCT coefficients will experimented. The comparison can be perform between the original image and the decompressed image.

In the Image processing toolbox, the two dimensional discrete cosine transform (DCT) of an image is c computed with dct2 function .The DCT has the property, most of the visually significant information about the image is concentrated in just a few coefficients of the DCT for a typical image. Thus, the DCT is often used in image compression applications.

Ways to compute the DCT, the image processing toolbox offers two different. First is to use dct2 function which uses an FFT based algorithm for quick computation with large inputs. It may be more efficient to use the DCT transform matrix, which is returned by the function dctmtx for small square inputs, such as 8-by-8 or 16-by-16. The M-by-M transform matrix T is given by:

T*A is an M-by-M matrix whose columns which have one dimensional DCT of the columns of A. The two dimensional DCT of A can be computed as,B=T*A*T’, where T’ is the transpose of T. Its inverse is the same as its transpose since T is a real orthonormal matrix.Thus, T’*B*T is the inverse two dimensional DCT of B.

The input image is divided into 8-by-8 or 16-by-16 blocks, and the two dimensional DCT is computed for each block for JPEG image compression algorithm. DCT coefficients are quantized, coded, and transmitted. Then, the quantized DCT coefficients, compute the inverse two-dimensional DCT of each block, and then puts blocks back together into a single image decodes by JPEG receiver. Many of the DCT coefficients have values close to zero for typical images. The quality of the reconstructed image is maintain eventhough these coefficients can be discarded.

T = dctmtx(8);

Mask=[ 1 1 1 1 0 0 0 0

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 ];

A = imread(‘cameraman.tif’);

A = double(A)/255;

B = blkproc(A, [8 8], ‘P1*x*P2’, T, T’);

C = blkproc(B,[8 8], ‘P1.*x’,Mask);

D = blkproc(C, [8 8], ‘P1*x*P2’, T’, T);

imshow(A), figure, imshow(D);

The mini program above, Observe and understand

The grayscale image ‘cameraman.tif’ is compressed and decompressed according to the code above

The difference between the original image and the reconstructed image is observe. Are there any difference noticeable?

observe on the quality of the reconstructed image with several different quantization matrices. What if quantization matrix having all the elements in the is set to 1?

Can all of the DCT coefficients be removed except for the DC value without affecting the quality of the reconstruct images by too much? Discuss your answer.

The above experiments is repeated using ‘rice.tif’ image.

compression and decompression of the grayscale image ‘cameraman.tif’

cameraman

Original image

19

Reconstructed image

After compression, the reconstructed image does not preserve the quality in the original image as it look blurer. This is caused the part which is set to ‘0’ in the quantization matrix during compression.

Matlab Code : image compression and decompression by using 8x8 DCT matrix.

T = dctmtx(8);

Mask=[ 1 1 1 1 0 0 0 0

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 ];

A = imread(‘cameraman.tif’);

A = double(A)/255;

B = blkproc(A, [8 8], ‘P1*x*P2’, T, T’);

C = blkproc(B,[8 8], ‘P1.*x’,Mask);

D = blkproc(C, [8 8], ‘P1*x*P2’, T’, T);

If all the elements in the quantization matrix is set to 1:

cameraman

Original image

cameraman

Reconstructed image

The Reconstructed image and the Original image are the same .This is caused by when all the parts in the quantization matrix are all set to ‘1’. Thus, no compression is done.

Matlab Code : image compression and decompression by using 8x8 DCT matrix.

T = dctmtx(8);

Mask=[ 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1];

A = imread('cameraman.tif');

A = double(A);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D = blkproc(C, [8 8], 'P1*x*P2', T', T);

imshow(uint8(A)), figure, imshow(uint8(D));

If remove all of the DCT coefficients except for the DC value

cameraman

Original image

20

Reconstructed image

We are unable to remove all the DCT coefficient except the DC value without affecting the quality of the reconstructed image. This is because when the DCT coefficient are removed, the high frequency are removed as well. Thus, information are lost. With the DCT gone,it is at a high compression ratio and high quality drop. With this, a very blur with blocking effect image is reconstructed.

Matlab Code : image compression and decompression by using 8x8 DCT matrix.

T = dctmtx(8);

Mask=[ 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

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 ];

A = imread('cameraman.tif');

A = double(A);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D = blkproc(C, [8 8], 'P1*x*P2', T', T);

imshow(uint8(A)), figure, imshow(uint8(D));

compression and decompression of the grayscale image ‘rice.tif’

rice

Original image

Fullscreen capture 2172009 112125 AM

Reconstructed image

The reconstructed image is blurred and the quality is reduced. This result is the same as the result of ‘camera.tif’.

Matlab Code : image compression and decompression by using 8x8 DCT matrix.

T = dctmtx(8);

Mask=[ 1 1 1 1 0 0 0 0

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 ];

A = imread('rice.tif');

A = double(A);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D = blkproc(C, [8 8], 'P1*x*P2', T', T);

imshow(uint8(A)), figure, imshow(uint8(D));

If all the elements in the quantization matrix is set to 1:

rice

Original image

rice

Reconstructed image

The Reconstructed image and the Original image are the same . This result is the same as the result of ‘camera.tif’.

Matlab Code : image compression and decompression by using 8x8 DCT matrix.

T = dctmtx(8);

Mask=[ 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1];

A = imread('rice.tif');

A = double(A);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D = blkproc(C, [8 8], 'P1*x*P2', T', T);

imshow(uint8(A)), figure, imshow(uint8(D));

If remove all of the DCT coefficients except for the DC value

rice

Original image

Reconstructed image

The reconstructed image is very blurred. . This result is the same as the result of ‘camera.tif’.

Matlab Code : image compression and decompression by using 8x8 DCT matrix.

T = dctmtx(8);

Mask=[ 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

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 ];

A = imread('rice.tif');

A = double(A);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D = blkproc(C, [8 8], 'P1*x*P2', T', T);

imshow(uint8(A)), figure, imshow(uint8(D));

The color image ‘peppers.png’ is loaded into Matlab. They are first converted to the YCbCr color format, followed by sub-sampling of the chrominance (Cb & Cr) channels for the compression of color images. Use the function rgb2ycbcr and ycbcr2rgb to convert to YCbCr color space and vice versa. Use the function imresize to sample the chrominance channels. Use the same mask as in the code above for both the luminance and chrominance channels.

Without any sub-sampling ,perform the DCT and quantization on all the channels then reconstruct the image and the quality of the image is observed.

Using the 4:2:0 chroma sub-sampling,perform the DCT and quantization on every channel then reconstruct the image and the quality of the image is observed.

Any significant differences between the two reconstructed images are there above? Discuss your answer.

A simple function is written that takes an image and a mask as the input, perform compression and decompression on the image (color image compression if input image is color), and display the original and reconstructed images side by side. the SNR of the reconstructed image should be able to compute by the program.

1)DCT and quantization on all the channels without any sub-sampling.

peppers

Original image

23

Compress in RGB format

21

Compress in YCbCr format

Matlab Code : image compression and decompression

T = dctmtx(8);

Mask=[ 1 1 1 1 0 0 0 0

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 ];

A = imread('peppers.png');

YCbCr = rgb2ycbcr(A);

YCbCr = double(YCbCr);

Y = YCbCr(:,:,1);

Cb = YCbCr(:,:,2);

Cr = YCbCr(:,:,3);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D(:,:,1) = blkproc(C, [8 8], 'P1*x*P2', T', T);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D(:,:,2) = blkproc(C, [8 8], 'P1*x*P2', T', T);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D(:,:,3) = blkproc(C, [8 8], 'P1*x*P2', T', T);

RBG = ycbcr2rgb(uint8(D));

figure, imshow(uint8(D)), figure, imshow(RBG);

2)DCT and quantization on every channel using the 4:2:0 chroma sub-sampling.

24

Compress in RGB format

25

Compress in YCbCr format

Matlab Code : image compression and decompression

T = dctmtx(8);

Mask=[ 1 1 1 1 0 0 0 0

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 ];

A = imread('peppers.png');

YCbCr = rgb2ycbcr(A);

YCbCr = double(YCbCr);

Y = YCbCr(:,:,1);

Cb = YCbCr(:,:,2);

Cr = YCbCr(:,:,3);

Cb = imresize(Cb,0.5);

Cr = imresize(Cr,0.5);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D(:,:,1) = blkproc(C, [8 8], 'P1*x*P2', T', T);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D(:,:,2) =imresize(blkproc(C, [8 8], 'P1*x*P2', T', T),2);

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

C = blkproc(B,[8 8], 'P1.*x',Mask);

D(:,:,3) =imresize(blkproc(C, [8 8], 'P1*x*P2', T', T),2);

RBG = ycbcr2rgb(uint8(D));

figure, imshow(uint8(D)), figure, imshow(RBG);

Comparing the DCT and quantization images in RGB and YCbCr without sub-sampling with the DCT and quantization images with 4:2:0 chroma sub-sampling, there is no difference between them. This is because, the human eye is less sensitive towards Cb and Cr compare to Y, luminance. Even the Cb and Cr is reduced, there are no visible difference the human eye can detect.

3) simple function that takes an image and a mask as the input, perform compression and decompression on the image

function [disp,snr]=codec_snr(file_name,mask)

clear D

A = imread(file_name);

T = dctmtx(8);

if isgray(A)

A = double(A);

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

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

D = blkproc(C, [8 8], 'P1*x*P2', T', T);

disp = uint8(D);

elseif isrgb(A)

YCbCr = rgb2ycbcr(A);

YCbCr = double(YCbCr);

Y = YCbCr(:,:,1);

Cb = imresize(YCbCr(:,:,2),0.5);

Cr = imresize(YCbCr(:,:,3),0.5);

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

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

D(:,:,1) = blkproc(C, [8 8], 'P1*x*P2', T', T);

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

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

D(:,:,2) =imresize(blkproc(C, [8 8], 'P1*x*P2', T', T),2);

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

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

D(:,:,3) =imresize(blkproc(C, [8 8], 'P1*x*P2', T', T),2);

disp = ycbcr2rgb(uint8(D));

end

A = imread(file_name);

sx = double(A).^2;

sd = (double(A)-double(disp)).^2;

snr = 10*log10(mean(sx(:))/mean(sd(:)));

figure('Position',[8 8 1000 500]),subplot(1,2,1),imshow(A);

text(0,0,'Before','HorizontalAlignment','center', 'BackgroundColor',[1 1 1]);

subplot(1,2,2), imshow(disp);

text(0,0,'After','HorizontalAlignment','center', 'BackgroundColor',[1 1 1]);

Discussion:

1.In this experiment, we are finding out how does the image compression works using DCT and quantization and sub-sampling method and how all these affect the quality of the images.

2. JPEG is an effective scheme for compressing photographic image as it reduces information of the image while maintaining image quality. It takes out information that is less sensitive to the human eye thus reducing the size of the file image. By using the right quantization scheme, image quality is preserved.

3. Compression efficiency = (file size of compressed image)/ (file size of original image)

4. Compressed image is stored as quantized DCT coefficients are a suitable approach. The human eye is sensitive to see differences in brightness in large area, but less sensitive to the strength of high frequency brightness variation. The DCT and quantization is used reduce the higher frequency components while avoid losing image quality. 

5. Low frequency is important follow by medium and follow by high frequency. The low frequency is perceptually important thus, require fine quantization.

6. The effect of reducing the number of DCT coefficients on the compression ratio and the image quality is that, the compression ratio increased but the image quality is reduce if the compression ratio is very high. When the quantization matrix has many elements that reduce a high number of high frequency components to zero, the higher the compression ratio. Due to the high reduction of DCT coefficient, some of the information is lost which causes the image to have block effect and quality is reduced.

8. In this experiment, we learned that DCT and quantization can be used for image compression. Different types of quantization matrix can affect the image compression. Sub-sampling can increase the compression ratio. Certain information can be reduce during compression as our eyes are only sensitive to certain information. Certain frequency is more important than the others and required finer quantization.

In the audio experiment, we are able to observe how a sample sound can be recorded while maintaining it’s quality. We are able to understand how each method work and some of their advantages over another. Speech requirement of good recording is lower than music.

In the image compression experiment we are able to understand how different method of compression works and being applied.



This is Preview only. If you need the solution of this assignment, please send us email with the complete assignment title: ProfessorKamranA@gmail.com