Week 4:

advertisement
Multimedia Programming
Week 7, Assignment 06
Coding and Compression
Teachers: Francois Lauze and Sune Keller
Group:
Ravikumar Kemapaih
Kent Gillette
Thabet Al Assadi
Theoretical Exercise:
Problem 1: Explain lossless coding.
Ans: Lossless coding commonly refers to coding methods that are completely reversible, that
is coders where in the original signal can be reconstructed bit for bit. The main aim of this
coding is to reduce the amount of source information to be transmitted in such a way that,
when the compressed information is decompressed, there is no loss of information. These
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 1 of 9
algorithms do not diminish the original audio quality in the slightest, because the original
audio material can be exactly reconstructed, so in other words it is reversible.
Lossless
coding is mainly used in applications like high quality downloading or streaming, in-studio
processing, and archiving or storage media like DVD. Lossless coding is of great interest
with the digitization, restoration and storage of old recordings.
Problem 2: Explain perceptual coding.
Ans: Perceptual coding uses a model of destination, that is the human being who will be
using data, rather than the model of the signal source. Perceptual coding attempts to remove
the parts of the signal that the human cannot perceive. Perceptual encoders, however, have
been designed for the compression of general audio such as the associated with a digital
television broadcast. They also use a model but, in this case, it is known as a psychoacoustic
model since its role is to exploit a number of the limitations of the human ear.
This is a lossy coding method. The in perceptible information removed by the perceptual
coders is called irrelevancy of the signal.
Most perceptual coders try to remove both
irrelevancy and redundancy in order to make a coder that provides the lowest bit rate possible
for a given audio quality. In general, perceptual coders will have a lower SNR than a source
coder, and higher perceived quality than a source coder of equivalent bit rate.
Problem 3: Explain the principle of I-, B- and P-frames in video coding (MPEG).
Ans: MPEG uses a series of I, B, and P frames which make up a “Group of Pictures”. An “I”
Frame is made up of one video frame and it stands all by itself. A “P” frame is a predicted
frame, and is based on past I frames. A “B” frame is a bi-directional frame made up of
information from both “I” frames and “P” frames. The basic idea is that since it is highly
likely that the “next” frame of any video will be very much like the “current” frame (the sky
will still be blue; for example), it is possible to predict portions of a future frame. Since it is
possible to predict what a frame might look like several frames away from the “current”
frame, it is also possible to calculate what the frames “in between” should look like.
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 2 of 9
Fig 1: Encoding and transmission order1
Problem 4: How would the following sequence be run-length encoded and what percentage
smaller is the run-length encoded data?
Sequence: 111112223333312222221111111333333333
Ans: Uncompressed: 111112223333312222221111111333333333 = 36 character
Compressed:
1!5 2!3 3!5 1 2!6 1!7 3!9 = 25 character with space as delimiter
Compression percentage = (36 – 25 / 36)*100% = 25 %
Problem 5: Suppose all odd symbols in the previous problem are replaced by 1, and all even
symbols are replaced by 0. Is there a further compressed coding which can be defined and
what percentage smaller is this scheme relative to the original binary sequence?
Ans: Uncompressed: 111110001111110000001111111111111111
Compressed:
1!5 0!3 1!6 0!6 1!16 = 20 characters with space character as a delimiter
Compression percentage = (36 – 20 / 36)*100% = 44.4 %
From the above we can see that there is further compressed coding with about 44% less size
from the original binary sequence. If the message format can always starts with 1 then
followed by 0, then the compressed string can be as following: 5 3 6 6 16= 10 characters and
compression rate can be 72 %
1
http://www.cs.cf.ac.uk/Dave/Multimedia/node258.html
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 3 of 9
Problem 6: Calculate the coding efficiency of the following code: Symbols a,b,c,d,e
P(a)
P(b)
P(c)
P(d)
P(e)
code
code
code
code
code
= .5
= .4
= .05
= .03
= .02
for a
for b
for c
for d
for e
=
=
=
=
=
00
01
11
100
101
Ans: The entropy can be calculated using Shannon’s formula
n
Entropy, H   Pi log 2 Pi bits per code word
i 1
H  0.5  log 2 0.5  0.4  log 2 0.4  0.04  log 2 0.04  0.03  log 2 0.03  0.02  log 2 0.02
H = 1.4792 bits per codeword
Average number of bits per codeword using Huffman coding is:
2  0.5  2  0.4  2  0.05  3  0.03  3  0.02  2.08 bits per codeword which is 71.12% of
the Shannon value.
Using fixed-length binary code words:
There are 5 characters, hence 3 bits per codeword is sufficient which is 69.33% of the
Huffman value.
Using 7-bit ASCII code words:
7 bits per codeword, which is 29.71% of the Huffman value.
Problem 7: Calculate the coding efficiency of the following code: Symbols a,b,c,d,e
P(a)
code
code
code
code
code
= .3 P(b) = .2 P(c) = .2 P(d) = .2 P(e) = .1
for a = 00
for b = 01
for c = 11
for d = 100
for e = 101
Ans: The entropy can be calculated using Shannon’s formula
n
Entropy, H   Pi log 2 Pi bits per code word
i 1
H  (0.3  log 2 0.3  3(0.2  log 2 0.2)  0.1 log 2 0.1)
H = 2.2464 bits per codeword
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 4 of 9
Average number of bits per codeword using Huffman coding is:
2  0.3  2  2  0.2  3  0.2  3  0.1  2.3 bits per codeword
which is 97.67 % of the Shannon value.
Using fixed-length binary code words:
There are 5 characters, hence 3 bits per codeword is sufficient which is 76.67 % of the
Huffman value.
Using 7-bit ASCII code words:
7 bits per codeword, which is 32.86 % of the Huffman value.
Problem 8: Calculate the coding efficiency of the following code: Symbols a,b,c,d,e all
have probabilities .2
code
code
code
code
code
for
for
for
for
for
a
b
c
d
e
=
=
=
=
=
00
01
11
100
101
Ans: The entropy can be calculated using Shannon’s formula
n
Entropy, H   Pi log 2 Pi bits per code word
i 1
H  (5  0.2  log 2 0.2)  H = 2.3219 bits per codeword
Average number of bits per codeword using Huffman coding is:
3  2  0.2  2  3  0.2  2.4 bits per codeword
which is 96.75 % of the Shannon value.
Using fixed-length binary code words:
There are 5 characters, hence 3 bits per codeword is sufficient which is 80 % of the Huffman
value.
Using 7-bit ASCII code words:
7 bits per codeword, which is 30 % of the Huffman value.
Practical exercises
Exercise 1 : Programming lossless compression (advanced programming)
Skipped
Exercise 2: Testing lossless compression
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 5 of 9
Exercise 2a:
We choose pdf file with size = 2.06 Mb
Size after normal compression: 1.48 Mb
Compression ratio using normal compression = (2.06-1.48/2.06)*100 = 28.1%
Size after maximum compression: 1.47 Mb =
Compression ratio using max compression = (2.06-1.48/2.06)*100 = 28.6 %
After using normal and maximum compression in WinZip the result shows that there is a
small difference in size between the normal and max compression.
Exercise 2b:
We choose tif file with size = 3.45 Mb
Size after normal compression: 2.13 Mb
Compression ratio using normal compression = (3.45-2.13/3.45)*100= 38.2%
Size after maximum compression: 2.09 Mb
Compression ratio using normal compression = (3.45-2.09/3.45)*100= 39.4%
After using normal and maximum compression on tif file the result shows that we can notice
the difference in size between the normal and max compression.
Exercise 2c:
A text based file always uses lossless compression techniques, because it is essential to
retrieve the original text. All these techniques require uneven distribution of text within the
message. When a message contains characters that are evenly distributed it might be
impossible to compress the file.
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 6 of 9
General speaking Winzip uses one or more of lossless compression techniques. Assuming
that Winzip compresses a file using RLE technique, it encodes the file by removing the
redundant character from it. Repeating the process will not compress the file any more since
the redundant characters have already been removed.
Exercise 2d: Lossy compression of MPEG
The source code of the function used to convert images to mpeg format and compress them
into a ratio of: 25, 50, 75, 90 %.
function compress2MPEG (image)
%% Compress any Image To MPEG
%Load the image into MatLab:
temp=imread(image);
%Creating new file name for each compression ratio, by
%cancadinating the ratio with the original image name:
imageQuality10 = sprintf('%s_10.jpg',image);
imageQuality25 = sprintf('%s_25.jpg',image);
imageQuality50 = sprintf('%s_50.jpg',image);
imageQuality75 = sprintf('%s_75.jpg',image);
imageQuality90 = sprintf('%s_90.jpg',image);
%This code takes an image and converts it to 5 mpeg format according to
%compression quality:
imwrite(temp,imageQuality10,'jpeg','quality',10);
imwrite(temp,imageQuality25,'jpeg','quality',25);
imwrite(temp,imageQuality50','jpeg','quality',50);
imwrite(temp,imageQuality75,'quality',75);
imwrite(temp,imageQuality90,'jpeg','quality',90);
File name
Compression Ratio %
New Size
fruit.tif (1.2 Mb)
10
17 Kb
25
28 Kb
50
41 Kb
75
57 Kb
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 7 of 9
text.gif (172 Kb)
tiger.gif (256 Kb)
90
93 Kb
10
41 Kb
25
71 Kb
50
106 Kb
75
145 Kb
90
207 Kb
10
49 Kb
25
81 Kb
50
119 Kb
75
163 Kb
90
232 Kb
From the above experiment we noticed that lossy is much more suitable for colored images.
The compression ratio for the colored image has no great effect on the new compressed file,
while it shows a clear difference in the quality on the gray (black and white) images. In case
of text it became nearly unreadable even with 90% compression ratio. Furthermore we even
noticed that the “compressed file” is bigger than the original file.
Before Compression:
After compression: Here it is visible that there is a
loss of data during compression
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 8 of 9
Before compression:
After Compression: again it’s a lossy compression
MMMP_Assignment_07
Ravi Kumar, Kent Gillette and Thabet Al Assadi.
Page 9 of 9
Download