Module - 3
Q)Explain JPEG coding Principles with neat diagram.
JPEG Encoder
• JPEG is an international image compression standard defined in IS 10918.
• It is mainly used for compressing digital images in multimedia communication.
• JPEG supports different compression modes.
• Lossy Sequential Mode (Base Mode) is commonly used for monochrome and color
images.
Main Stages of JPEG Encoder
JPEG encoder consists of 5 stages:
1. Image / Block Preparation
2. Forward DCT
3. Quantization
4. Entropy Encoding
5. Frame Building
JPEG Encoder Block Diagram
Input Image
│
▼
Image / Block Preparation
│
▼
Forward DCT
│
▼
Quantization
│
▼
Entropy Encoding
(Vectoring + Differential Encoding +
Run-Length Encoding + Huffman Encoding)
│
▼
Frame Building
│
▼
Compressed JPEG Bitstream
1. Image / Block Preparation
• The source image is represented using one or more 2D matrices.
• Monochrome image uses one matrix of 8-bit gray-level values.
• RGB color image uses three matrices:
o R
o G
o B
• YCbCr format can also be used.
• Chrominance signals require less bandwidth than luminance signal.
• Before compression, image is divided into small:
8×8
blocks.
• Each block is processed separately.
2. Forward DCT (Discrete Cosine Transform)
• Pixel values are normally in the range:
o 0 to 255 for luminance values
o -128 to +127 for chrominance values
• Before applying DCT, 128 is subtracted from each pixel value to center values around
zero.
• DCT converts image data from spatial domain into frequency domain.
DCT Formula
7
1 7 (2𝑥 + 1)𝑖𝜋 (2𝑦 + 1)𝑗𝜋
𝐹[𝑖, 𝑗] = 𝑐(𝑖)𝑐(𝑗) ∑ ∑ 𝑃[𝑥, 𝑦]cos cos
4 𝑦=0 16 16
𝑥=0
Where:
• 𝑃[𝑥, 𝑦]= input matrix
• 𝐹[𝑖, 𝑗]= transformed matrix
Important Points
• 𝐹[0,0]is called DC coefficient.
• DC coefficient represents average intensity value.
• Remaining values are AC coefficients.
3. Quantization
• Quantization maps large coefficient values into smaller discrete values.
• JPEG uses:
o luminance quantization table
o chrominance quantization table
• High-frequency coefficients become zero after quantization.
• Quantized values are rounded to nearest integer.
Purpose
• Main lossy compression step.
• Reduces image size greatly.
4. Entropy Encoding
Entropy encoding contains four stages:
(a) Vectoring
• Quantized 2D matrix is converted into a 1D vector.
• Zig-zag scanning is used.
• Zig-zag scan groups zeros together for better compression.
(b) Differential Encoding
• Only difference between consecutive DC coefficients is encoded.
• Reduces number of bits required.
Example
Original values:
12, 13, 11, 11, 10
Difference values:
12, 1, -2, 0, -1
(c) Run-Length Encoding
• Long runs of zeros are compressed.
• AC coefficients are represented as:
(skip, value)
• Skip represents number of zeros.
(d) Huffman Encoding
• Frequently occurring values get shorter codewords.
• Rare values get longer codewords.
• Uses Huffman coding algorithm.
• Provides efficient lossless compression.
5. Frame Building
• Final compressed data is organized into JPEG frame format.
• Entire image information is enclosed between:
o Start-of-frame
o End-of-frame
Frame Header Contains
• Image width and height
• Type of image components:
o CLUT
o RGB
o YCbCr
• Digitization format:
o 4:2:2
o 4:2:0
Scan Header Contains
• Identity of image components
• Number of bits used
• Quantization tables used
Advantages of JPEG Encoder
• High compression ratio
• Good image quality
• Reduces storage space
• Faster transmission
• Widely used in multimedia applications
Q)Explain jpeg decoding technique.
JPEG Compression Technique
JPEG is the most widely used image compression standard used for digital images
and multimedia applications.
It reduces image size while maintaining good image quality.
JPEG Compression Steps
JPEG compression mainly consists of the following stages:
1. Image / Block Preparation
2. Forward DCT
3. Quantization
4. Entropy Encoding
5. Frame Building
JPEG Compression Block Diagram
Input Image
│
▼
Image / Block Preparation
│
▼
Forward DCT
│
▼
Quantization
│
▼
Entropy Encoding
(Vectoring + Differential Encoding +
Run-Length Encoding + Huffman Encoding)
│
▼
Frame Building
│
▼
Compressed JPEG Bitstream
1. Image / Block Preparation
• The source image is represented as 2D matrices.
• Monochrome image uses one matrix.
• RGB color image uses three matrices:
o R
o G
o B
• YCbCr format can also be used.
• Chrominance signals require less bandwidth than luminance signal.
• Each matrix is divided into small:
8×8
blocks.
• Each block is compressed separately.
2. Forward DCT (Discrete Cosine Transform)
• Before DCT, 128 is subtracted from each pixel value to center values around zero.
• DCT converts spatial image data into frequency-domain data.
• All 64 values of the block contribute to transformed coefficients.
DCT Formula
7
1 7 (2𝑥 + 1)𝑖𝜋 (2𝑦 + 1)𝑗𝜋
𝐹[𝑖, 𝑗] = 𝑐(𝑖)𝑐(𝑗) ∑ ∑ 𝑃[𝑥, 𝑦]cos cos
4 𝑦=0 16 16
𝑥=0
Where:
• 𝑃[𝑥, 𝑦]= input matrix
• 𝐹[𝑖, 𝑗]= transformed matrix
Important Points
• 𝐹[0,0]is called DC coefficient.
• Remaining values are AC coefficients.
• DC coefficient represents average intensity.
• AC coefficients represent frequency components.
3. Quantization
• Quantization maps large coefficient values into smaller values.
• JPEG uses separate quantization tables for:
o luminance
o chrominance
• High-frequency coefficients become zero after quantization.
• Coefficients are rounded to nearest integer.
Advantages
• Main lossy compression step.
• Reduces image size greatly.
4. Entropy Encoding
Entropy encoding contains four stages:
(a) Vectoring
• Quantized matrix is converted into a 1D vector.
• Zig-zag scanning is used.
• Zig-zag scan groups zeros together.
(b) Differential Encoding
• Only difference between successive DC coefficients is encoded.
Example
Original DC values:
12, 13, 11, 11, 10
Difference values:
12, 1, -2, 0, -1
• Reduces number of bits required.
(c) Run-Length Encoding
• Long runs of zeros are compressed.
• AC coefficients are encoded as:
(skip, value)
Example:
(0,6) (0,7) (0,3)
(d) Huffman Encoding
• Frequently occurring values get shorter codewords.
• Rare values get longer codewords.
• Uses Huffman coding algorithm.
• Provides efficient lossless compression.
5. Frame Building
• Final compressed image is organized into JPEG frame format.
• Frame contains:
o image width and height
o image components
o quantization tables
o digitization format
• Entire image data is enclosed between:
o Start-of-frame
o End-of-frame
JPEG Decoder
• Decoder performs reverse operations:
1. Huffman decoding
2. Run-length decoding
3. Differential decoding
4. Dequantization
5. Inverse DCT
6. Image reconstruction
Progressive JPEG Modes
1. Progressive Mode
• Sends low-frequency coefficients first.
• Higher-frequency details added later.
2. Hierarchical Mode
• Sends low-resolution image first.
• Higher-resolution image sent later.
Advantages of JPEG
• High compression ratio
• Good image quality
• Reduced storage requirement
• Faster image transmission
• Widely used in multimedia systems