๐ผ️ JPEG Image Compression
B.Sc. Computer Science Honours – Image Processing & Data Compression
๐ 1. Introduction to JPEG
JPEG stands for Joint Photographic Experts Group. It is one of the most widely used image compression standards for photographic and natural images.
JPEG compression primarily exploits two important properties of images:
- Spatial redundancy between neighbouring pixels.
- Psychovisual redundancy caused by limitations of human vision.
๐ท 2. Interactive JPEG Demonstration
Upload an image to inspect the major stages of JPEG-style processing.
๐ผ️ 3. Original and Grayscale Image
Original Image
Grayscale Image
๐ฒ 4. 8 × 8 Image Block
JPEG processes an image in small blocks. The classical JPEG transform uses an 8 × 8 pixel block.
The selected block below is converted to grayscale values and shifted by 128 before applying the DCT.
๐ 5. Discrete Cosine Transform (DCT)
The DCT converts spatial pixel information into frequency-domain coefficients.
where:
- f(x,y) = spatial-domain pixel value.
- F(u,v) = DCT coefficient.
- u,v = frequency indices.
- C(0) = 1/√2.
- C(k) = 1 for k > 0.
The upper-left coefficient F(0,0) is the DC coefficient. The remaining coefficients are called AC coefficients.
๐ฏ 6. Quantization
Quantization is the main lossy stage of JPEG compression. Each DCT coefficient is divided by a corresponding value in a quantization matrix and rounded to an integer.
where T(u,v) is the quantization matrix.
↘️ 7. Zig-Zag Scanning
After quantization, the 8 × 8 coefficient matrix is rearranged using a zig-zag scan.
The zig-zag ordering places low-frequency coefficients near the beginning and high-frequency coefficients toward the end.
High-frequency coefficients are often quantized to zero, creating long runs of zeros that can subsequently be compressed efficiently.
๐ 8. Complete JPEG Compression Pipeline
The exact JPEG process contains additional details, but these stages represent the main conceptual pipeline taught in image processing and data compression courses.
๐ 9. Detailed Theory for B.Sc. Computer Science Honours
9.1 Why Does JPEG Compress Images?
Digital images contain a large amount of redundant information. Neighbouring pixels in natural images are often strongly correlated. JPEG transforms this spatial redundancy into frequency coefficients and then represents visually less important information with reduced precision.
9.2 RGB to YCbCr
JPEG commonly uses the YCbCr colour representation. The image is separated into:
- Y – luminance component.
- Cb – blue-difference chrominance component.
- Cr – red-difference chrominance component.
Human vision is generally more sensitive to changes in brightness than to fine chrominance detail. Therefore, chroma components can often be sampled at a lower resolution.
9.3 Chroma Subsampling
JPEG can reduce the spatial resolution of chrominance components using schemes such as:
- 4:4:4
- 4:2:2
- 4:2:0
For example, 4:2:0 uses fewer chroma samples relative to luminance. This reduces the amount of information that needs to be encoded.
9.4 Blocking
The image is divided into blocks, traditionally 8 × 8 pixels. Each block is processed independently by the DCT.
Block processing makes the transform computationally manageable and allows frequency information to be represented locally.
9.5 Level Shifting
For an 8-bit image, pixel values normally range from 0 to 255. Before applying the DCT, JPEG conceptually shifts the values by 128:
Therefore the transformed values approximately range from −128 to +127.
9.6 Frequency Components
The DCT represents the block using different spatial frequencies.
- Low frequencies: gradual changes and broad image structures.
- High frequencies: rapid changes, edges and fine details.
The DC coefficient represents the average level of the block, while AC coefficients describe variations around that average.
9.7 DC and AC Coefficients
AC → F(u,v), where (u,v) ≠ (0,0)
The DC coefficient is normally encoded relative to the DC coefficient of the previous block. AC coefficients are processed using the zig-zag order and run-length representation.
9.8 Quantization and Loss
Quantization is responsible for the principal information loss in baseline JPEG.
Consider:
Quantization value = 10
83 / 10 = 8.3
round(8.3) = 8
The original value 83 cannot generally be reconstructed exactly from the quantized value 8 and the quantization value 10.
9.9 Zig-Zag Ordering
A typical zig-zag sequence starts near the DC coefficient and gradually moves toward higher-frequency coefficients.
This arrangement tends to group many zero-valued high-frequency coefficients near the end of the sequence after quantization.
9.10 Run-Length Coding in JPEG
After zig-zag scanning, quantized AC coefficients are represented using run-length concepts.
A typical representation describes:
where RUNLENGTH specifies the number of preceding zero coefficients.
The special EOB (End of Block) symbol can indicate that the remaining coefficients in the block are zero.
9.11 Entropy Coding
JPEG commonly uses entropy coding after quantization and zig-zag processing. In baseline JPEG, Huffman coding is commonly used.
Thus, JPEG combines transform coding, quantization, run-length representation and entropy coding.
9.12 JPEG Compression Ratio
The compression ratio can be expressed as:
Higher compression usually requires stronger quantization, which can increase visible distortion.
9.13 JPEG Quality Factor
Many JPEG software tools expose a quality setting. A higher quality setting generally corresponds to less aggressive quantization and larger files, while lower quality settings generally use stronger quantization and produce smaller files.
The exact mapping between a software quality value and the resulting JPEG quantization tables is implementation-dependent.
9.14 JPEG Artifacts
Strong JPEG compression can introduce visible artifacts, including:
- Blocking artifacts
- Ringing near sharp edges
- Loss of fine texture
- Blurring
- Colour distortions
9.15 Advantages of JPEG
- Excellent for photographic and natural images.
- Provides substantial file-size reduction.
- Supported by almost all image-processing platforms.
- Allows adjustable compression quality.
- Uses well-studied transform and entropy coding techniques.
- Suitable for web images, photography and digital media.
9.16 Limitations of JPEG
- Standard JPEG compression is lossy.
- Repeated recompression can accumulate visible degradation.
- Not ideal for line drawings or images containing sharp text.
- Strong compression can produce blocking artifacts.
- Fine details may be lost during quantization.
9.17 JPEG vs Lossless Compression
| Feature | JPEG | Lossless Compression |
|---|---|---|
| Information loss | Normally lossy in photographic JPEG compression | No information loss |
| Compression | Can achieve high compression | Usually lower compression for natural images |
| Quantization | Yes | No lossy quantization |
| Typical use | Photographs and natural images | Medical, technical or archival data where exact recovery matters |
9.18 Important Examination Points
- JPEG stands for Joint Photographic Experts Group.
- JPEG is primarily designed for photographic and natural images.
- JPEG commonly uses the 8 × 8 DCT.
- DCT converts spatial information into frequency coefficients.
- The DC coefficient is F(0,0).
- Other coefficients are AC coefficients.
- Quantization is the principal lossy stage.
- Zig-zag scanning orders quantized coefficients.
- Run-length and entropy coding further reduce the representation.
- JPEG commonly uses YCbCr and may use chroma subsampling.
- High compression can produce blocking and other visual artifacts.
๐ 10. Image Information
๐ง 11. JPEG Concept Summary
The central idea is to transform image data into frequency components, reduce the precision of less visually significant information, and then encode the resulting coefficients efficiently.
No comments:
Post a Comment