Elective Image Processing

Image ProcessingUnit 29 min read

Image Sampling & Quantization: Pixels, Resolution & Color Depth

Unit 2 of Image Processing covers how analog images become digital pixels through sampling (spatial resolution) and quantization (color depth), including pixel relationships, Nyquist theorem, color models (RGB, grayscale), and storage calculations with real-world examples from eSewa, Daraz, and medical imaging.

TAKEAWAYS:

  • Sampling converts spatial coordinates into discrete pixels via the Nyquist theorem (sampling rate ≥ 2× highest frequency).
  • Quantization maps continuous intensity values to discrete levels (e.g., 8-bit = 256 grayscale shades).
  • Pixel relationships define resolution: width × height × bits per pixel = total storage (e.g., 1024×768×24 = 2.25 MB).
  • Color models (RGB, CMYK, grayscale) determine quantization depth and file size trade-offs.
  • Aliasing occurs when undersampling distorts high-frequency details (e.g., jagged edges in low-res images).
  • Real-world impact: eSewa’s ID photos use 300 DPI (sampling) and 24-bit RGB (quantization) for clarity; Daraz thumbnails use 72 DPI to balance speed and storage.

1. Digital Image Formation: Sampling Spatial Coordinates

-10-8-6-4-2246810-2-1123456xyOriginal Signal (Sinc Function)Aliased Signal (Undersampled)Nyquist LimitAliasing Artifact
Nyquist theorem: Sampling rate (0.5) < 2× highest frequency (1) causes aliasing.

How Analog Images Become Pixels

An analog image (continuous light intensity) is converted to a digital image by:

  1. Sampling: Measuring light intensity at discrete points (pixels) across x and y axes.
  2. Quantization: Assigning each sampled value to a finite set of discrete levels (e.g., 0–255 for 8-bit grayscale).

Key Definitions

  • Pixel (Picture Element): Smallest addressable unit in a digital image, defined by its spatial coordinates (row, column) and intensity value.
  • Spatial Resolution: Number of pixels along width/height (e.g., 1920×1080 = Full HD).
  • Sampling Rate: Pixels per unit length (e.g., 72 pixels/inch = PPI/DPI for printers).

Nyquist Sampling Theorem

To avoid aliasing (false high-frequency artifacts), the sampling rate must be at least twice the highest frequency in the image: Example: A 300 DPI scanner samples at 300 pixels/inch. If the highest spatial frequency in the image is 150 cycles/inch, → no aliasing.

graph LR
    A["Analog Image\n(Continuous Light)"] -->|"Sampling"| B["Discrete Pixels\n(Spatial Grid)"]
    B -->|"Quantization"| C["Digital Image\n(Discritized Intensity)"

Real-World Example: eSewa ID Photos

  • Sampling: 300 DPI (1 pixel = 1/300 inch) to capture fine facial details.
  • Why? Undersampling (e.g., 72 DPI) would cause aliasing (jagged edges around hair/eyes), making verification harder.
  • Quantization: 24-bit RGB (8 bits per channel) for color accuracy.

2. Quantization: Mapping Intensity to Discrete Levels

How Many Levels?

Quantization converts continuous intensity to discrete levels :

  • = bits per pixel (e.g., → 256 levels).
  • Grayscale: 0 (black) to 255 (white).
  • RGB: 3 bytes (8 bits each for R, G, B).

Color Depth vs. File Size

Bits per Pixel Levels per Channel Colors (RGB) File Size (1024×768)
1 2 8 0.75 MB
8 (grayscale) 256 256 0.75 MB
24 256 16.7 million 2.25 MB
32 256 4.3 billion 3 MB

Example Calculation: For a 1028×1028 image with 512 colors (9-bit quantization): (9 bits = 1.125 bytes per pixel; 512 colors = )

Real-World Example: Daraz Product Images

  • Thumbnails: 72 DPI × 8-bit grayscale (0.25 MB) for fast loading.
  • High-res: 300 DPI × 24-bit RGB (2.25 MB) for zoomable details.
  • Trade-off: Lower quantization (e.g., 16-bit) reduces file size but loses color fidelity.

3. Pixel Relationships and Image Storage

Neighborhood Operations

Pixels are related via 8-neighborhood (including diagonals) or 4-neighborhood (only horizontal/vertical):

8-neighborhood:
A B C
D E F
G H I
  • E is the center pixel; A–I are neighbors.
  • Used in edge detection (e.g., Sobel operator) and morphological operations.

Storage Formula

Total image size (bytes) = width × height × bits per pixel / 8. Example: A 2048×1536 grayscale image (8 bits/pixel):

Real-World Example: Medical Imaging (X-rays)

  • Sampling: 100–200 DPI to detect fine bone structures.
  • Quantization: 12-bit grayscale (4096 levels) for high contrast.
  • Why? Low quantization (e.g., 8-bit) would lose subtle tissue differences.

4. Aliasing and Its Effects

graph LR
    A[High-Res Image
(300 DPI)] -->|Downsampled
(72 DPI)| B[Aliased
(Jagged Edges)]
    B -->|Anti-Aliasing
(Gaussian Blur)| C[Smooth
(No Artifacts)]
Aliasing in Daraz product thumbnails (72 DPI) vs. anti-aliased versions.

Cause: Undersampling

When , high frequencies appear as false low frequencies (e.g., jagged edges). Example: Zooming a low-res image reveals "staircase" artifacts.

graph TD
    A["High-Frequency\nSignal"] -->|"Undersampled"| B["Aliased\nLow-Frequency\nArtifact"]

Real-World Example: Kathmandu Traffic Signs

  • Problem: Low-resolution CCTV cameras (e.g., 640×480) undersample license plates, causing aliasing in number recognition.
  • Solution: Use 1280×720+ resolution and anti-aliasing filters (e.g., Gaussian blur before downsampling).

5. Color Models and Quantization

Grayscale (8-bit) (10%)RGB (24-bit) (70%)CMYK (32-bit) (15%)Indexed (8-bit) (5%)
Nepali digital media color model usage (2023): WhatsApp (RGB), medical scans (Grayscale), printing (CMYK).

Common Models

Model Channels Quantization Bits Use Case
Grayscale Intensity 8 Medical imaging, scans
RGB Red, Green, Blue 8 each (24 total) Digital photos, web
CMYK Cyan, Magenta, ... 8 each (32 total) Printing
Indexed Palette lookup 1–8 GIFs, low-storage images

Real-World Example: WhatsApp Profile Pictures

  • Quantization: 24-bit RGB (16.7M colors) for vibrant displays.
  • Sampling: 480×480 pixels (scaled from higher-res uploads).
  • Trade-off: Smaller thumbnails (e.g., 96×96) use dithering to simulate colors with fewer bits.

6. Worked Example: Calculating Image Size

Problem: A 512-color image has dimensions 1028×1028. Calculate its size in MB. Solution:

  1. Determine bits per pixel: 512 colors = → 9 bits/pixel.
  2. Calculate total bits: bits.
  3. Convert to bytes/MB: bytes ≈ 1.13 MB.

7. Exam Tip: Common Pitfalls and Focus Areas

  • Sampling vs. Quantization:

    • Sampling = spatial resolution (pixels/inch).
    • Quantization = color depth (bits/pixel).
    • Exam trick: Questions often mix these—always specify which is being asked!
  • Nyquist Theorem:

    • Memorize: .
    • Example: If cycles/inch, DPI.
  • File Size Calculations:

    • Use the formula: width × height × (bits/pixel) / 8.
    • Shortcut: For 24-bit RGB, divide by 8 first (3 bytes/pixel).
  • Aliasing:

    • Always mention jagged edges or moiré patterns as visual clues.
    • Example: "A 72 DPI scan of a 300 DPI photo will show aliasing."
  • Color Models:

    • RGB is for screens; CMYK for print.
    • Exam tip: "Indexed color" uses a palette (e.g., GIFs).

Labelled illustration of an analog-to-digital conversion pipeline showing a continuous image sampled into a pixel grid, then quantized to discrete intensity levels.

Side-by-side comparison of a properly sampled image vs. an aliased version with jagged edges (e.g., a circle appearing square).

In the real world

  • eSewa ID Photos: Uses 300 DPI sampling (Nyquist-compliant for facial details) and 24-bit RGB quantization to ensure clear biometric verification, avoiding aliasing in edge regions (eyes, hairlines).
  • Daraz Product Images: Thumbnails use 72 DPI × 8-bit grayscale (0.25 MB) for fast loading, while high-res versions use 300 DPI × 24-bit RGB (2.25 MB) to balance storage and zoomable detail.
  • NTC Traffic Cameras: Low-resolution CCTV (640×480) causes aliasing in license plates, requiring anti-aliasing filters (Gaussian blur) before downsampling for OCR accuracy.

Based on the TU BCA syllabus for Image Processing, unit 2.

Discussion

Loading…