MMC Unit II
MMC Unit II
By
M.C.Aralimarad
Text and Image Compression in Multimedia Applications
• Where:
• nnn = number of different symbols.
• PiP_iPi= probability of occurrence of symbol iii.
• Huffman Encoding:
• A lossless data compression algorithm.
• Assigns shorter codes to more frequent characters, and longer codes to less frequent
characters.
• Efficient for compressing text and image data.
Huffman Encoding Example
•Figure 3.4 (Huffman Encoding Example):
•Code Generation Process:
•Example characters with probabilities:
•A = 0.25, B = 0.25, C = 0.14, D = 0.14, E = 0.11, F = 0.055, G = 0.055, H = 0.055
•The Huffman tree is constructed by combining the lowest-probability nodes.
•Codewords Derived:
•Shorter codes for frequent characters, e.g., A = 1, B = 01
•Longer codes for less frequent characters, e.g., F = 00001, G = 00000
• Huffman Code Tree
• Figure 3.4(b) (Huffman Code Tree):
• Visual representation of how Huffman codes are derived.
• Nodes combined in ascending order of weight:
• Leaf nodes: Represent characters with weights (probabilities).
• Internal nodes: Sum of the probabilities of connected nodes.
• The tree structure ensures the prefix property:
• No code is a prefix of another, ensuring unique decodability.
Huffman Decoding Process
•Figure 3.5 (Decoding Process):
•Decoding Flowchart (Figure 3.5(a)):
•The bitstream is processed sequentially to identify valid codewords.
•Steps:
1.Retrieve bits from the BIT-STREAM.
2.Append bits to CODEWORD variable.
3.Check if CODEWORD matches a valid code.
4.If yes, write ASCII character to RECEIVE_BUFFER; if no, continue.
•Example Decoding (Figure 3.5(b)):
•Decoding a bitstream: 10111000001…
•Extracted characters: A, B, B, A, D
•Shows sequential decoding based on valid codewords.
• Key Properties of Huffman Codes
• Prefix Property:
• Ensures that no codeword is a prefix of another.
• Prevents ambiguity during decoding; each codeword can be uniquely
decoded.
• Efficiency:
• Huffman codes minimize the average code length, optimizing storage and
transmission efficiency.
• Applications:
• Widely used in text compression (e.g., ZIP files) and image formats (e.g.,
JPEG).
• Dynamic Huffman Coding:
Introduction to Dynamic Huffman Coding
• A variation of Huffman coding where codewords are updated as new characters are transmitted.
• Eliminates the need for a predefined frequency table at the start.
• Allows efficient, adaptive compression, especially useful when data characteristics change over
time.
• Mechanism of Dynamic Huffman Coding
• Operation:
• Both transmitter and receiver start with an initial tree structure, consisting of a root node and a
single empty leaf node (with zero frequency).
• As each character is encountered, its frequency is updated, and the tree is adjusted.
• Codewords adapt in real time as characters are transmitted, with the tree structure modified
dynamically at both the transmitter and receiver.
• Advantages of Dynamic Huffman Coding
• Advantages:
• Reduces overhead by adapting the code structure to the incoming data stream.
• No need to transmit a frequency table beforehand; the receiver can reconstruct the tree on-the-fly.
• Useful for data with varying frequency distributions, enabling efficient, real-time compression.
Dynamic Huffman Encoding Algorithm
• LZ Compression Basics:
• A dictionary-based compression technique.
• Uses strings of characters rather than single characters.
• Encoding Method:
• Encoder sends the index of a word's location in the dictionary.
• Decoder reconstructs text based on these indices.
• LZ Coding and Practical Applications
• Applications in Word Processing:
• Many word processors use LZ for compression.
• Dictionary contains approximately 25,000 words.
• Compression Efficiency:
• Example: The word "multimedia" requires only 15 bits with a dictionary, compared to 70
bits with ASCII encoding.
• Compression Ratio: Achieves a ratio of 4.7:1, where shorter words achieve lower ratios.
• Lempel-Ziv Algorithm (Example 3.3)
• Dictionary-Based Compression:
• Uses a dictionary with 4096 entries for text compression.
• Compression ratio example: 3.5:1 for ASCII codewords.
• Efficiency:
• Higher efficiency with a dynamic dictionary approach.
• Lempel-Ziv–Welch (LZW) Coding
• Dynamic Dictionary Construction:
• Dictionary builds up during encoding.
• Both encoder and decoder update dictionary simultaneously.
• Key Idea:
• Reduces redundancy by storing repeated sequences.
• Example sequence: "This is simple as it is…".
• Slide 9: LZW Coding Process (Fig 3.8)
• Basic Operation:
• Initial dictionary contains character set (e.g., ASCII).
• New words added dynamically (e.g., "This", "is", "simple").
• Dynamic Expansion:
• Incremental indexing for added words.
• Extended LZW Dictionary (Fig 3.8b)
• Dictionary Expansion:
• Dictionary expanded to accommodate new sequences.
• Efficient storage and retrieval using dynamic indexing.
• Example:
• Dictionary initially starts with individual characters.
• Extends with multi-character sequences as compression progresses.