5 Data Compression

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.

Data Compression: notes

Storage Space

Uncompressed audio and video need far more storage than the equivalent compressed data, and transmitting them uncompressed over a digital network is correspondingly harder, since it demands much higher bandwidth for even a single point-to-point link. Multimedia systems therefore use compressed formats for digital audio and video, cheaper to store and practically feasible to transmit; JPEG for still pictures, H.265 for video, and the MPEG family for combined video and audio are among the most widely used.

Coding Requirements

Images already need more storage than text, and audio and video are more demanding again, so any compression scheme is subject to strict limits: whatever is lost, the decompressed result must stay as close to the original as possible. Two usage patterns set different numerical requirements. A dialogue mode application, where humans interact through multimedia information, needs an end-to-end delay below 150 ms, and below 50 ms for genuinely face-to-face use, since larger delays make live conversation feel unnatural. A retrieval mode application, where a user retrieves stored information from a multimedia database, instead needs fast forward and backward retrieval with simultaneous display, fast search, and random access to a single image or audio frame within under 0.5 seconds.

Source, Entropy and Hybrid Coding

Compression techniques fall into three families:

CategoryApproachExamples
Entropy codingLossless, ignores what the data meansRun-length coding, Huffman coding, arithmetic coding
Source codingLossy, exploits the meaning of the dataPrediction (DPCM, delta modulation), transformation (DCT, FFT), layered coding (subsampling, sub-band coding), vector quantization
Hybrid codingCombination of entropy and source codingJPEG, MPEG, H.261, DVI

Entropy coding is lossless: decompression regenerates the data exactly, treating the data purely as a digital sequence with no regard for what it represents.

Run-length encoding (RLE) replaces a run of at least four consecutive occurrences of the same byte with three bytes: the byte value, an exclamation-mark flag, and the number of repetitions. Encoding ABCCCCCDDDDF (12 bytes: one A, one B, five C's, four D's, one F) gives ABC!5D!4F (9 bytes), and decoding reverses this exactly: A and B are copied literally, C!5 expands to CCCCC, D!4 expands to DDDD, and F is copied literally, reconstructing ABCCCCCDDDDF, byte for byte. RLE only helps when data repeats: encoding AABCCD (6 bytes) with a straightforward one-count-per-run scheme gives A2B1C2D1 (8 bytes), which is larger than the input, showing that RLE can expand data with little repetition.

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

2081 · 5 marks

Differentiate between JPEG and MPEG. [5]

JPEG (Joint Photographic Experts Group) and MPEG (Moving Picture Experts Group) are both hybrid coding standards used in multimedia systems, combining entropy and source coding techniques. However, they differ significantly in their purpose, process, and application. --- Aspect JPEG MPEG --------...

Open this answer on its own page →

2080 · 10 marks

Explain the JPEG compression process steps in detail with example.[10]

JPEG (Joint Photographic Experts Group) is a widely used lossy compression standard for still images. It is best suited for photographic/web images where a trade-off between image quality and file size is acceptable. The amount of compression can be controlled, making it highly flexible. JPEG is ...

Open this answer on its own page →

Source, Entropy and Hybrid Coding

2081 · 5 marks

Compare between lossless compression with lossy compression. [5]

Lossless Compression is a data compression technique in which the original data can be perfectly reconstructed from the compressed data without any loss of information. Lossy Compression is a data compression technique in which some amount of data is permanently lost during compression, and the o...

Open this answer on its own page →

2080 · 10 marks

What do you mean by Huffman coding? Explain the Huffman coding process with example.[10]

Show solved 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

CharacterFrequency
A2
B3
C2
D4
E2

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:

CharacterPath from RootHuffman CodeCode Length
ELeft, Left002 bits
BLeft, Right012 bits
ARight, Left, Left1003 bits
CRight, Left, Right1013 bits
DRight, Right112 bits

Step 6: Calculate Compression

Total bits with Huffman coding:

CharacterFrequencyCodeBits Used
A21002 x 3 = 6
B3013 x 2 = 6
C21012 x 3 = 6
D4114 x 2 = 8
E2002 x 2 = 4
Total1330 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

  1. It is lossless -- original data is perfectly recovered.
  2. It produces optimal prefix-free codes.
  3. It is widely used in JPEG, MPEG, ZIP and other multimedia compression standards.
  4. 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.

Open this answer on its own page →