Grayscale Intensity Transformations
In digital image processing, a grayscale image is represented mathematically as a two-dimensional discrete matrix f(x, y), where each spatial coordinate (x, y) corresponds to a quantized intensity level r lying within the bounded interval [0, L - 1] (typically [0, 255] for standard 8-bit unsigned integer channels). Point processing transformations modify individual pixel values through a transfer mapping function s = T(r) without taking spatial neighborhood kernels into account.
Mathematical Foundations of Contrast Stretching
Low-contrast images frequently result from poor illumination conditions, dynamic range limitations of image sensors, or incorrect aperture settings during photographic acquisition. Linear contrast stretching expands the narrow dynamic range [r_min, r_max] of an input image across the entire available intensity spectrum [s_min, s_max] (typically [0, 255]):
s = ((r - r_min) / (r_max - r_min)) * (s_max - s_min) + s_min
To prevent extreme outlier pixels from compressing the useful visual range, percentile-based histogram stretching computes low (e.g., 2nd percentile) and high (e.g., 98th percentile) cutoff thresholds. All pixel intensities below the low threshold or above the high threshold are clipped prior to linear remapping.
Cumulative Distribution Function (CDF) Equalization
Histogram equalization is an automated point-processing technique designed to linearize the cumulative distribution function (CDF) of an image, producing an output image with an approximately uniform probability density function (PDF). For a discrete image containing N total pixels and L = 256 discrete intensity bins:
p_r(r_k) = n_k / N, for k = 0, 1, ..., L - 1
s_k = T(r_k) = (L - 1) * SUM(p_r(r_j)) from j = 0 to k
Because digital intensities are integer-quantized, the discrete transformation maps each input level r_k to the nearest integer round((L - 1) * CDF(r_k)). This redistributes clumped frequency clusters across the dynamic range, revealing fine shadow and highlight details.
Histogram Matching Algorithms
While standard histogram equalization yields a uniform histogram, many computer vision and medical imaging applications require an image to conform to a specific non-uniform target distribution (such as Gaussian bell curves or multi-modal target profiles). Histogram specification (matching) establishes a monotonic mapping between the source cumulative distribution CDF_src(r) and the target reference distribution CDF_tgt(z):
1. Compute normalized CDF_src(r) for all r in [0, 255]
2. Compute normalized CDF_tgt(z) for the target reference image
3. For each intensity level r, find the smallest z such that CDF_tgt(z) >= CDF_src(r)
4. Remap pixels using lookup table: s(x, y) = mapping[r(x, y)]
This method aligns illumination profiles between multiple sensor feeds, normalizes training data distributions for machine learning pipelines, and standardizes multi-spectral satellite imagery.