Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
EBU5303 Multimedia Fundamentals
Introduction
This lab is common to EBU6018 and EBU5303.
In Part 1 of the lab you will:
Investigate the Wavelet transform and its filter bank implementation for discrete-time signals
Apply the Haar Discrete Wavelet Transform to compress signals.
Marks will go towards the assessment of EBU6018.
In Part 2 of the lab you will implement a simple JPEG encoder / decoder. Marks will go towards the assessment of EBU5303.
The MATLAB programming outcomes from the lab (i.e., MATLAB .m function files and plot figures) are to be handed in as a “folder” of results, showing that you have completed the steps of the lab successfully.
You must also answer some questions directly within this document, which must be saved and submitted with other outcomes in your folder of results.
You must submit your combined report to BOTH EBU6018 AND EBU5303 QM+ course areas.
Part 1 (EBU6018)
1 The Wavelet Transform: Introduction
In EBU6018 lectures, we introduced the wavelet transform, defined in terms of the wavelet’s scaling function wavelet function. In those lectures we used Haar Functions as the wavelet function to perform a Discrete Wavelet Transform (DWT).
We also saw that for a discrete-time signal, the Discrete Wavelet Transform (DWT) can be
implemented as a sequence of filtering followed by downsampling. Using this filterbank we do not need to calculate the mother wavelet ?(t) , we only need the coefficients of the low-pass and high-pass filters ?and
Various files are provided for this lab.
2 DWT of an input vector s[n].
2.1 Discrete Wavelet Transform Filter Bank
Download the file dwt_haar.m. This implements a Haar Discrete Wavelet Transform using
filtering (convolution) and subsampling.
Explain how this Matlab function works in the text box provided, and check that it implements a normalised Haar DWT using the recursion formulas given in the lecture notes and used in tutorial examples.
Test this function by taking the Haar DWT of the following signal, to 2 steps:
s = [-2, 5, 3, -1, 4, -3, 1, 2]
Check the following (and record the values in the text box and save the plots obtained ):
(a) The “length” (Matlab: norm) of the DWT of s, and check it is the same as for s itself.
(b) The first half of the DWT of s contains (scaled) sums of pairs of elements of s, while the
second half contains scaled differences of pairs of elements of s.
(c) The one-step DWT of s is the same as multiplying s (actually the column vector s’) by the following matrix:
Hints: Make sure you always give row vectors to this simple dwt_haar() function.
We are using dyadic scaling so the number of elements in the input vector is a power of 2.
2.2 Inverse DWT Filter Bank
Download the file idwt_haar.m , which implements the inverse DWT.
Apply this to the sequencies you transformed in the previous section. Explain what happens in the text box provided.
Explain how this Matlab function works, and check that it implements a recursion formula similar to the synthesis equation given in the lecture slide on the signal recovery filterbank.
Put your explanations in the text box provided and save your plots to confirm that the original sequence is obtained by applying the function idwt_haar.m.
3 Signal Compression using the DWT
This exercise is to generate a test signal, plot its DWT, then compress the signal by discarding small values. By reducing the number of non-zero values the result is that fewer bits are needed to represent it. However, the result is some distortion of the original signal.
Download the files: testsig.m, compress.m, uncompress.m, comp_ratio.n.
The file testsig.m generates the following signal:
Modify the file testsig.m so that the first part is now
3.1 Plot this signal and its DWT for 4 levels.
Plot the signal from the modified testsig.m and then its DWT after 1, 2, 3 and then 4 steps of decomposition
3.2 Compress the signal
Applying the file compress.m will compress this signal by transforming it and setting all values below a threshold to zero.
The file uncompress.m inverts the transform carried out by compress.m.
Modify the files compress.m and uncompress.m to include your transform of the signal where indicated.
Plot the original modified signal, the 4-step DWT, the 4-step DWT after thresholding , the reconstructed signal from the inverse DWT and also the error introduced by the DWT thresholding (the difference between the original signal and the reconstructed one). Save the plots obtained.
Part 2 (EBU5303)
4. Image preparation
a.Create a MATLAB function in the file “myJPEG.m”. Read the RGB image file
Monkey.png using the imread MATLAB function and display it with the imshow function.
b.Add code to myJPEG.m to retrieve the pixel dimensions of the image (width x height) and calculate the number of 8x8 blocks of pixels contained in each of the R, G, and B channel (eliminating any remaining pixels).
c.In myJPEG.m, extract the three colour channels (R, G, B) from the original image. Save the three channels as three separate jpeg images in your folder of results.
d.In myJPEG.m, convert the RGB image into Ycbcr. Extract the three channels (Y, cb, cr) and save everything (Ycbcr_image, Y_channel, cb_channel, cr_channel) as separate jpeg images in your folder of results.
e.In myJPEG.m, for each of the R, G, B, Y, cb, and cr channel, and working from left to right, top to bottom, split the matrix of pixels into 8x8 blocks of pixels. Comment your code.
f.Print (disp) the first 8x8 matrix of pixel values for each of the 6 channels (R, G, B, Y, cb, and cr).
g.In myJPEG.m, subtract 128 from each pixel values so they range from -128 to 127.
5. Applying 2D DCT to each block
a.In myJPEG.m, working from left to right, top to bottom, apply the 2D DCT MATLAB function (dct2) to each block of pixel values (for the R, G, B, cb, and cr channels). Save the results in 8x8 matrices of DCT coefficients values. Comment your code.
b.Print (disp) the first 8x8 matrix of DCT coefficients values for the R, G, and B channels.
6. Quantisation (RGB image)
a.In myJPEG.m, declare a standard quantisation matrix named Qstd using the values of the matrix shown below.
= Qstd
b.In myJPEG.m, apply standard quantisation to the 8x8 matrices of DCT coefficients for the R, G, and B channels, using Qstd. Comment your code.
Hint: quantisation is achieved by dividing each DCT coefficient by the corresponding element in the quantisation matrix, and then rounding to the nearest integer value.
c.Print (disp) the first 8x8 matrix of quantised DCT coefficients for each of the R, G, and B channels.
d.In myJPEG.m, create one more quantisation matrix for high quantisation (Qhigh). Comment your code.
Hint: use a quantisation factor to multiply Qstd. The scaled matrix must then be rounded and clipped to have positive integer values ranging from 1 to 255.
e. Print (disp) Qhigh and explain how you created the high quantisation matrix (i.e., what quantisation factor you chose and why).
f.In myJPEG.m, apply high quantisation to the 8x8 matrices of DCT coefficients for the R, G, and B channels, using Qhigh.
g.Print (disp) the 8x8 matrix of quantised DCT coefficients (high quantisation) or each channel (R, G, and B).
h.Compare the 6 matrices obtained in part c. (standard quantisation) and g. (high quantisation) and comment. Discuss how the choice of quantisation matrix might affect the compression rate.
7. Quantisation (Ycbcr image)
a.In myJPEG.m, apply (1) standard, then (2) high quantisation to the DCT coefficients of the cb and cr channels only, using Qstd and Qhigh respectively. Do not quantise the matrices of the Y (luminance) channel.
b.Print (disp) side by side the first 8x8 matrix of quantised DCT coefficients (standard quantisation on the left, high quantisation on the right) for each of the cb and cr channels.
8. Decompression
a.In myJPEG.m, multiply the quantised DCT values of all compressed channels (R, G, B, cb, and cr) by the quantisation matrix you used for quantisation (standard or high). Comment your code.
b.Print (disp) side by side the first 8x8 matrix of restored DCT coefficients for the R, G, B channels (standard quantisation on the left and high quantisation on the right).
c.Compare the six matrices above with the matrices of Question Q5b. (coefficients before quantisation). Comment and explain.
d.In myJPEG.m, apply the inverse DCT (idct2) to all 8x8 matrices of DCT coefficients for all channels (standard and high quantisation, R, G, B, Y, cb, cr). Don’t forget to add 128 to each matrix element and to round the values. Comment your code.
e.Print (disp) the first 8x8 matrix of reconstructed pixel values for the three R, G, B channels, (standard quantisation on the left and high quantisation on the right).
f.Compare the six matrices above with the matrices of Question Q4f. (original pixel values). Comment and explain.