Image Basics

Module 2 - Pixels, Color Spaces, and Histograms

Pixels and Channels

A digital image is a 2D array of pixels. Each pixel holds a value representing light intensity. For a grayscale image, one number per pixel (0 = black, 255 = white). For color images, three numbers per pixel - one per channel.

In memory, a 640×480 RGB image is stored as a 3D tensor of shape (480, 640, 3) - height × width × channels.

Pixel Inspector

Move your mouse over the image to inspect pixel values.

Move over image

Color Spaces

Different color spaces represent color in different ways. The choice affects what operations are easy or hard.

Color Space Explorer

SpaceValues

Image Histograms

A histogram counts how many pixels have each intensity value (0–255). It summarizes the tonal distribution of an image at a glance.

Live Histogram Generator

Histogram Equalization

A classic technique to improve contrast: redistribute pixel values so the histogram becomes flat (uniform). Works well on underexposed photos.

CDF(v) = Σ hist(i) for i = 0..v
Symbol guide
CDF(v)Cumulative Distribution Function at value v - how many pixels have intensity ≤ v
va specific pixel intensity level, from 0 (black) to 255 (white)
Σ (sigma)summation - add up all the terms that follow
hist(i)histogram count - how many pixels in the image have intensity exactly equal to i
i = 0..vloop variable: sum from intensity 0 up to and including intensity v
CDF(v) / total_pixels × 255remapping step - scales the cumulative count to the 0–255 output range

The equalized value of a pixel v is: round(CDF(v) / total_pixels × 255)

Equalization Demo

Original
Equalized
Histograms (before / after)

Quiz

Check your understanding

1. What is the shape (tensor dimensions) of a 1920×1080 RGB image in memory?

2. You want to detect a red ball regardless of lighting. Which color space is best?

3. A histogram has almost all values concentrated in the range 100–150. What does this suggest?