Multimedia Module No: CM0340 Laboratory Worksheet Lab 6 (Week 8): MATLAB GIF/ LZW and JPEG Compression Prof. D. Marshall Aims and Objectives After working through this worksheet you should be familiar with: • GIF/LZW Compression Algorithm • JPEG Compression Process • The basic use of MATLAB to investigate the above. None of the work here is part of the assessed coursework for this module 1 MATLAB GIF/ LZW and JPEG Compression 1. GIF/ LZW Compression. (a) • Download the Basic Compression Algorithms MATLAB Zipped Files from the CM0340 web pages: http://www.cs.cf.ac.uk/Dave/Multimedia/ Lecture Examples/Basic Compression.zip. • Uncompress and install in an appropriate MATLAB acces- sible directory. • Launch MATLAB and cd to the lzw directory. (b) The demo file lzw_demo1.m reproduces the example discussed in the lecture notes: http://www.cs.cf.ac.uk/Dave/Multimedia/PDF/ 09 CM0340 Basic Compression Algorithms.pdf. • Open the file in MATLAB – Examine the lzw_demo1.m code and familiarise your- self with the functions called and the variables used. (c) Run lzw_demo1.m example and note the output. • Note the variables created in MATLAB. • Examine the packed and table (A MATLAB Cell Array) variables. Explain the data stored in these variables with relation to the example data. • Examine the norm2lzw.m LZW encoder function code. Com- pare this to the pseudocode given in lecture. Notice how the packed and table variables are constructed and used here. • Examine the lzw2norm.m LZW decoder function code. Com- pare this to the pseudocode given in lecture. Note how it processed the input LZW code. (d) Input and encode/decode your own character sequences. Note how the variables packed and table are set accordinlgy. Try and design sequences that build up a set of repetitions to see the code working most effectively. 2 2. JPEG Compression (a) • Download the JPEG Image Compression MATLAB Zipped Files from the CM0340 web pages http://www.cs.cf.ac.uk/Dave/Multimedia/Lecture Examples/jpeg.zip. • Uncompress and install in an appropriate MATLAB acces- sible directory. • Launch MATLAB and cd to the jpeg directory. • The directory should contain three files: – im2jpeg.m — JPEG encoder – jpeg2im.m — JPEG decode – mat2huff.m — Huffman coder – huff2matt.m — Huffman decoder • Open all files in MATLAB editor and familiarise with the code. • In im2jpeg.m pay particular attention to the variable m, order and functions mat2huff.m, dctmtx (see Laboratory Worksheet Lab 1 Questions 6 and 7, http://www.cs.cf.ac.uk/Dave/Multimedia/exercises BSC/lab1.pdf), blkproc and im2col. – Use MATLAB help to find out more about blkproc and im2col. (b) JPEG encoder/decoding in MATLAB: • Load in an image in MATLAB and encode it using im2jpeg.m. Note the structure used and the formats used. • Decode the above and store in a different image variable. • Compare the the two images by the following: – Visually: Display both images in MATLAB. – Compute the difference between the images and dis- play this result. – Compute the squared error between the images and dis- play this result. • Change the normalisation array m for different values and compare results as above: – See the lecture notes and handouts (on JPEG and MPEG) for different possible arrays. 3 ∗ See also the JAVA Applet demo (from lecture) for values for m: http://www.cs.sfu.ca/CourseCentral/365/li/interactive-jpeg/Ijpeg.html – Implement a constant value normalisation value 2,4,6, 8, 32 or 128 – Invent some values for m yourself - for JPEG to work ac- cording to specification m should implement a low pass filter but you could try other values? Additional Revision You may have noticed that the Basic Compression Algorithms MATLAB Zipped Files contain MATLAB implementation of other compression algorithms. Feel free to explore these. 4