Multimedia Computing · Unit 5 · 8 hrs
Data Compression
Exam-focused notes for Data Compression (Multimedia Computing, CSC330): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.
Data Compression in short
Uncompressed audio, image and video data are far too large to store or transmit economically, so this chapter covers why multimedia systems compress data, what that compression must guarantee, and how the major families of compression algorithm, entropy coding, source coding and the hybrid JPEG and MPEG standards, actually work.
What this unit covers
- Storage Space
- Coding Requirements
- Source, Entropy and Hybrid Coding
- Lossy Sequential DCT-based Mode
- Expanded Lossy DCT-based Mode
- JPEG and MPEG
JPEG and MPEG
2080 · 10 marks
Explain the JPEG compression process steps in detail with example.[10]
Source, Entropy and Hybrid Coding
2081 · 5 marks
Compare between lossless compression with lossy compression. [5]
2080 · 10 marks
What do you mean by Huffman coding? Explain the Huffman coding process with example.[10]
Show solved answerHide answer
Huffman Coding
Definition
Huffman coding is a lossless data compression technique and a type of entropy coding that assigns variable-length binary codes to input characters based on their frequency of occurrence. Characters that occur more frequently are assigned shorter codes, while characters that occur less frequently are assigned longer codes. This minimizes the total number of bits required to represent the data.
: "Run-length coding, Huffman coding, Arithmetic coding are entropy coding" and in JPEG entropy encoding, "Huffman coding is preferred as it is free."
Key Characteristics
- It is a lossless (hassless) compression method -- decompression regenerates data completely.
- It is based on the frequency/probability of characters in the data.
- It produces an optimal prefix code -- no code is a prefix of another code.
- It uses a binary tree structure called the Huffman Tree.
Huffman Coding Process (Algorithm)
The steps to build a Huffman code are:
Step 1: Count the frequency of each character in the input data.
Step 2: Create a leaf node for each character and insert all nodes into a min-priority queue (ordered by frequency, lowest first).
Step 3: While there is more than one node in the queue:
- Remove the two nodes with the lowest frequency (call them Left and Right).
- Create a new internal node with frequency = Left frequency + Right frequency.
- Assign the Left node as the left child and the Right node as the right child.
- Insert the new internal node back into the queue.
Step 4: The remaining single node is the root of the Huffman Tree.
Step 5: Assign binary codes by traversing the tree:
- Going Left = assign bit 0
- Going Right = assign bit 1
Step 6: The code for each character is the sequence of bits from the root to that leaf node.
Worked Example
Given Input String:
"AABBBCCDDDDEE"
Step 1: Calculate Frequencies
| Character | Frequency |
|---|---|
| A | 2 |
| B | 3 |
| C | 2 |
| D | 4 |
| E | 2 |
Total characters = 13
Step 2: Build Min-Priority Queue (sorted by frequency)
A(2), C(2), E(2), B(3), D(4)
Step 3: Build the Huffman Tree
Iteration 1: Pick two lowest: A(2) and C(2)
- Create internal node AC(4)
- Queue: E(2), B(3), AC(4), D(4)
AC(4)
/ \
A(2) C(2)
Iteration 2: Pick two lowest: E(2) and B(3)
- Create internal node EB(5)
- Queue: AC(4), D(4), EB(5)
EB(5)
/ \
E(2) B(3)
Iteration 3: Pick two lowest: AC(4) and D(4)
- Create internal node ACD(8)
- Queue: EB(5), ACD(8)
ACD(8)
/ \
AC(4) D(4)
/ \
A(2) C(2)
Iteration 4: Pick two lowest: EB(5) and ACD(8)
- Create root node EBACD(13)
- Queue: EBACD(13) -- only one node remains, this is the root
EBACD(13)
/ \
EB(5) ACD(8)
/ \ / \
E(2) B(3) AC(4) D(4)
/ \
A(2) C(2)
Step 4 and 5: Assign Codes (Left = 0, Right = 1)
Traverse from root to each leaf:
| Character | Path from Root | Huffman Code | Code Length |
|---|---|---|---|
| E | Left, Left | 00 | 2 bits |
| B | Left, Right | 01 | 2 bits |
| A | Right, Left, Left | 100 | 3 bits |
| C | Right, Left, Right | 101 | 3 bits |
| D | Right, Right | 11 | 2 bits |
Step 6: Calculate Compression
Total bits with Huffman coding:
| Character | Frequency | Code | Bits Used |
|---|---|---|---|
| A | 2 | 100 | 2 x 3 = 6 |
| B | 3 | 01 | 3 x 2 = 6 |
| C | 2 | 101 | 2 x 3 = 6 |
| D | 4 | 11 | 4 x 2 = 8 |
| E | 2 | 00 | 2 x 2 = 4 |
| Total | 13 | 30 bits |
Without Huffman coding (fixed 3-bit code for 5 characters):
- 13 characters x 3 bits = 39 bits
Compression achieved: 39 - 30 = 9 bits saved (approximately 23% compression)
Advantages of Huffman Coding
- It is lossless -- original data is perfectly recovered.
- It produces optimal prefix-free codes.
- It is widely used in JPEG, MPEG, ZIP and other multimedia compression standards.
- Frequently occurring symbols get shorter codes, reducing overall data size.
Summary
Huffman coding is a powerful entropy coding technique that exploits the statistical redundancy in the data by assigning shorter binary codes to more frequent characters and longer codes to rarer ones, while the prefix-free property of the resulting codes guarantees that the encoded bit stream can always be decoded unambiguously using the same binary tree that was built during encoding, without needing any separators between codes.
Make Unit 5 stick
Practice CSC330 with flashcards & quizzes