Skip to the content.

Measuring Contrast Between Two Color Images: Comparison Metrics and Methods

When working with image processing pipelines, quality assessment, or change detection systems, we often need to quantify how much the contrast differs between two images. This goes beyond measuring contrast within a single image—we need metrics that capture the difference in contrast characteristics between pairs of images. Such comparisons are crucial for evaluating image enhancement algorithms, detecting scene changes, assessing compression artifacts, and benchmarking computer vision systems.

Note: This post builds on concepts from Understanding Contrast in Images: From Perception to Computation and Understanding Contrast in Color Images: Beyond Luminance. If you’re new to contrast metrics, I recommend reading those posts first.

Table of Contents

1. Why Compare Contrast Between Images?

Contrast comparison between images is essential for numerous practical applications:

  • Algorithm Evaluation: Quantifying how much an enhancement algorithm improves contrast
  • Quality Assessment: Detecting contrast degradation due to compression, transmission errors, or sensor limitations
  • Change Detection: Identifying significant scene changes in surveillance or monitoring
  • Display Calibration: Ensuring consistent contrast rendering across different displays
  • Medical Imaging: Comparing diagnostic image quality across different acquisition protocols
  • Content Adaptation: Adjusting images for different viewing conditions while maintaining perceptual contrast

2. Problem Formulation

2.1. Image Pair Notation

Let’s denote two color images as $I_1$ and $I_2$, where:

  • $I_1(x, y) = [R_1(x, y), G_1(x, y), B_1(x, y)]$ is the reference image
  • $I_2(x, y) = [R_2(x, y), G_2(x, y), B_2(x, y)]$ is the comparison image
  • Both images have dimensions $M \times N$

For luminance-based comparisons, we convert to grayscale:

\[L_i(x, y) = 0.2126 R_i + 0.7152 G_i + 0.0722 B_i\]

2.2. Types of Contrast Differences

Contrast differences can manifest in several ways:

  1. Global contrast shift: Overall brightness range changes
  2. Local contrast variation: Spatial distribution of contrast changes
  3. Chromatic contrast difference: Color saturation or hue contrast changes
  4. Frequency-dependent contrast: Different contrast at different spatial scales

3. Pixel-Level Contrast Comparison Methods

3.1. RMS Contrast Difference

The simplest approach compares RMS contrast values:

\[C_{RMS}(I) = \frac{\sigma_L}{\bar{L}}\]

where $\sigma_L$ is the standard deviation and $\bar{L}$ is the mean luminance.

Absolute difference:

\[\Delta C_{RMS} = \mid C_{RMS}(I_2) - C_{RMS}(I_1) \mid\]

Relative difference (percentage):

\[\Delta C_{RMS}^{rel} = \frac{\mid C_{RMS}(I_2) - C_{RMS}(I_1) \mid}{C_{RMS}(I_1)} \times 100\%\]

Properties:

  • Simple and fast to compute
  • Single scalar value per image
  • Does not capture spatial distribution of contrast changes
  • Sensitive to mean luminance differences

3.2. Michelson Contrast Difference

For images with clear light and dark regions:

\[C_M(I) = \frac{L_{max} - L_{min}}{L_{max} + L_{min}}\] \[\Delta C_M = \mid C_M(I_2) - C_M(I_1) \mid\]

Properties:

  • Suitable for high-contrast patterns
  • Range: [0, 1]
  • Can be applied locally for spatial contrast maps

3.3. Local Contrast Difference Maps

Compute local contrast in sliding windows and compare pixel-by-pixel:

\[C_{local}(I, x, y) = \frac{\sigma_{w}(x, y)}{\mu_{w}(x, y)}\]

where $\sigma_{w}$ and $\mu_{w}$ are computed in a window $w$ centered at $(x, y)$.

Difference map:

\[D_{contrast}(x, y) = \mid C_{local}(I_2, x, y) - C_{local}(I_1, x, y) \mid\]

Aggregate metric:

\[\overline{\Delta C_{local}} = \frac{1}{MN} \sum_{x, y} D_{contrast}(x, y)\]

Properties:

  • Captures spatial variation in contrast differences
  • Window size affects sensitivity
  • Produces visualization-friendly difference maps
  • More computationally intensive

4. Histogram-Based Comparison

4.1. Histogram Distance Metrics

Chi-square distance:

\[\chi^2 = \sum_{i=0}^{255} \frac{(h_1(i) - h_2(i))^2}{h_1(i) + h_2(i)}\]

Bhattacharyya distance:

\[d_B = \sqrt{1 - \sum_{i=0}^{255} \sqrt{h_1(i) \cdot h_2(i)}}\]

where $h_1(i)$ and $h_2(i)$ are normalized histograms.

Earth Mover’s Distance (EMD):

Measures the minimum “work” required to transform one histogram into another, accounting for bin proximity.

Properties:

  • Histogram-based methods are invariant to spatial arrangement
  • Chi-square is sensitive to empty bins
  • Bhattacharyya distance is symmetric and bounded [0, 1]
  • EMD considers perceptual similarity between bins

4.2. Cumulative Distribution Comparison

Compare cumulative distribution functions (CDFs):

\[CDF(I, k) = \sum_{i=0}^{k} h(i)\]

Kolmogorov-Smirnov statistic:

\[D_{KS} = \max_{k} \mid CDF_1(k) - CDF_2(k) \mid\]

Properties:

  • Captures overall distribution shape
  • Sensitive to contrast stretching and compression
  • Less sensitive to local changes than histogram methods

5. Frequency Domain Analysis

5.1. Power Spectrum Comparison

Transform images to frequency domain using FFT:

\[F(u, v) = \mathcal{F}\{I(x, y)\}\]

Power spectrum:

\[P(u, v) = \mid F(u, v) \mid^2\]

Radial power spectrum:

\[P(r) = \frac{1}{N_r} \sum_{(u,v) \in \text{ring}(r)} P(u, v)\]

Comparison metric:

\[\Delta P = \sum_{r} \mid P_1(r) - P_2(r) \mid\]

Properties:

  • Captures contrast at different spatial frequencies
  • High frequencies correspond to fine details and edges
  • Low frequencies correspond to large-scale contrast
  • Can identify specific frequency bands where contrast differs

5.2. DCT Coefficient Analysis

For block-based analysis (useful in compression):

\[DCT(I) = \sum_{x=0}^{N-1} \sum_{y=0}^{M-1} I(x,y) \cos\left(\frac{\pi u}{N}(x + 0.5)\right) \cos\left(\frac{\pi v}{M}(y + 0.5)\right)\]

Compare AC coefficients (which represent contrast/detail):

\[\Delta_{DCT} = \sum_{u,v \neq (0,0)} \mid DCT_1(u,v) - DCT_2(u,v) \mid\]

Properties:

  • Natural for JPEG-compressed images
  • AC coefficients directly relate to contrast and detail
  • Can be weighted by visual importance

6. Perceptual Contrast Difference Metrics

6.1. SSIM-Based Contrast Component

The Structural Similarity Index (SSIM) decomposes into three components:

\[SSIM(x, y) = l(x, y) \cdot c(x, y) \cdot s(x, y)\]

where:

  • $l(x, y)$ is luminance comparison
  • $c(x, y)$ is contrast comparison
  • $s(x, y)$ is structure comparison

Contrast component:

\[c(x, y) = \frac{2\sigma_x \sigma_y + C_2}{\sigma_x^2 + \sigma_y^2 + C_2}\]

where $\sigma_x$ and $\sigma_y$ are local standard deviations, and $C_2$ is a stabilizing constant.

Properties:

  • Perceptually motivated
  • Bounded between -1 and 1
  • 1 indicates identical contrast
  • Computed locally and averaged

6.2. Multi-Scale Contrast Comparison

Analyze contrast at multiple scales using Gaussian pyramids:

\[I^{(s)} = G_{\sigma_s} * I\]

where $G_{\sigma_s}$ is a Gaussian kernel at scale $s$.

Multi-scale difference:

\[\Delta C_{MS} = \sum_{s=1}^{S} w_s \cdot \mid C(I_1^{(s)}) - C(I_2^{(s)}) \mid\]

where $w_s$ are scale-dependent weights.

Properties:

  • Captures contrast differences at different levels of detail
  • More robust to minor spatial misalignments
  • Mimics human visual system’s multi-scale processing

6.3. Color Appearance Model Differences

Transform to perceptual color spaces (CIELAB, CIECAM02):

CIELAB contrast difference:

For each pixel, compute $\Delta E$ color difference, then aggregate:

\[\Delta E_{00}(x, y) = \sqrt{\left(\frac{\Delta L'}{k_L S_L}\right)^2 + \left(\frac{\Delta C'}{k_C S_C}\right)^2 + \left(\frac{\Delta H'}{k_H S_H}\right)^2 + R_T \frac{\Delta C'}{k_C S_C} \frac{\Delta H'}{k_H S_H}}\]

CIECAM02 contrast attributes:

Compare lightness ($J$), chroma ($C$), and colorfulness ($M$) differences.

Properties:

  • Accounts for human color perception
  • More accurate for chromatic contrast differences
  • Computationally more expensive

7. Statistical Measures

7.1. Variance and Standard Deviation Ratios

Variance ratio:

\[R_{\sigma^2} = \frac{\sigma_2^2}{\sigma_1^2}\]

Values > 1 indicate increased contrast, < 1 indicate decreased contrast.

Log variance ratio (dB):

\[\Delta C_{dB} = 10 \log_{10}\left(\frac{\sigma_2^2}{\sigma_1^2}\right)\]

Properties:

  • Symmetric around 0 dB (no change)
  • Positive values indicate contrast increase
  • Negative values indicate contrast decrease
  • Common in signal processing

7.2. Contrast Sensitivity Function

Model human contrast sensitivity at different frequencies:

\[CSF(f) = a \cdot f \cdot e^{-b \cdot f}\]

Weighted frequency difference:

\[\Delta C_{CSF} = \sum_{f} CSF(f) \cdot \mid P_1(f) - P_2(f) \mid\]

Properties:

  • Weights differences by human visual sensitivity
  • Emphasizes mid-range frequencies
  • De-emphasizes very high and very low frequencies

8. Practical Comparison: Different Methods on Image Pairs

Let’s compare three image pairs to demonstrate different contrast comparison scenarios:

Image Pair Description RMS Contrast Diff Local Contrast Diff Histogram Chi-Square SSIM Contrast Component
A: Original vs. Enhanced Enhanced contrast through histogram equalization $\Delta C_{RMS} = 0.28$ $\overline{\Delta C_{local}} = 0.15$ $\chi^2 = 1250$ $\overline{c} = 0.72$
B: Original vs. Compressed JPEG compression at quality=30 $\Delta C_{RMS} = 0.05$ $\overline{\Delta C_{local}} = 0.08$ $\chi^2 = 350$ $\overline{c} = 0.91$
C: Day vs. Night Same scene, different illumination $\Delta C_{RMS} = 0.42$ $\overline{\Delta C_{local}} = 0.35$ $\chi^2 = 2800$ $\overline{c} = 0.45$

Observations:

  • Image Pair A shows significant global contrast increase (high RMS difference) with moderate local changes, indicating successful enhancement
  • Image Pair B has low RMS difference but higher local contrast degradation, typical of compression artifacts that preserve global statistics but degrade fine details
  • Image Pair C has the highest differences across all metrics, reflecting fundamental scene change

9. Applications

9.1. Image Enhancement Evaluation

Use case: Evaluating automatic contrast enhancement algorithms

Relevant metrics:

  • RMS contrast difference (should be positive, indicating increase)
  • Local contrast difference maps (to verify enhancement is uniform)
  • SSIM contrast component (to ensure no over-enhancement)

Decision criteria:

  • $0.1 < \Delta C_{RMS}^{rel} < 0.3$: Good enhancement
  • $\Delta C_{RMS}^{rel} > 0.5$: Possible over-enhancement
  • $\overline{c} < 0.8$: Structural artifacts introduced

9.2. Compression Quality Assessment

Use case: Determining optimal compression level

Relevant metrics:

  • Local contrast difference maps (detect blocking artifacts)
  • DCT coefficient differences (quantify frequency-specific losses)
  • Perceptual metrics (SSIM contrast, CIECAM02)

Decision criteria:

  • $\overline{\Delta C_{local}} < 0.05$: Imperceptible quality loss
  • $0.05 < \overline{\Delta C_{local}} < 0.15$: Acceptable quality
  • $\overline{\Delta C_{local}} > 0.2$: Noticeable degradation

9.3. Change Detection

Use case: Surveillance, remote sensing, medical imaging

Relevant metrics:

  • Local contrast difference maps (spatial change localization)
  • Multi-scale contrast comparison (scale-invariant detection)
  • Histogram-based metrics (scene-level changes)

Decision criteria:

  • Threshold difference maps to identify changed regions
  • Use multi-scale analysis to distinguish real changes from noise

9.4. Display Calibration and Matching

Use case: Ensuring consistent rendering across displays

Relevant metrics:

  • Michelson contrast ratios
  • CIELAB/CIECAM02 perceptual differences
  • Gamma curve comparison

Decision criteria:

  • Match contrast ratios within 5% tolerance
  • Perceptual differences below JND (Just Noticeable Difference)

10. Implementation Considerations

Computational Efficiency

Method Complexity Speed Memory
RMS Contrast Diff $O(MN)$ Very Fast Low
Local Contrast Maps $O(MNW^2)$ Slow High
Histogram-based $O(MN + B^2)$ Fast Low
FFT-based $O(MN \log(MN))$ Moderate Moderate
SSIM Contrast $O(MNW^2)$ Slow High
Multi-scale $O(SMN)$ Moderate High

Robustness Considerations

  • Spatial misalignment: Use registration or multi-scale methods
  • Illumination changes: Normalize images or use illumination-invariant features
  • Noise: Apply smoothing or use robust statistics (median instead of mean)
  • Scale differences: Resize images to same dimensions before comparison

Software Libraries

  • Python: OpenCV (cv2.calcHist, cv2.compareHist), scikit-image (structural_similarity), NumPy/SciPy (FFT, statistics)
  • MATLAB: Image Processing Toolbox (ssim, psnr, imhist)
  • C++: OpenCV, Eigen (matrix operations), FFTW (FFT)

11. Conclusion

Measuring contrast differences between two color images is a multi-faceted problem with no single “best” metric. The choice of method depends on:

  1. Application requirements: Real-time vs. offline, spatial detail vs. global assessment
  2. Image characteristics: Natural scenes vs. synthetic patterns, color vs. grayscale
  3. Computational resources: Embedded systems vs. cloud processing
  4. Perceptual goals: Matching human judgments vs. objective quantification

Key recommendations:

  • For enhancement evaluation: Use RMS contrast difference + SSIM contrast component
  • For compression assessment: Use local contrast difference maps + DCT analysis
  • For change detection: Use multi-scale contrast comparison + spatial thresholding
  • For display calibration: Use perceptual color models (CIELAB, CIECAM02)

By combining multiple metrics—global and local, spatial and frequency-domain, objective and perceptual—we can build robust systems for contrast comparison that align with both computational efficiency and human visual perception.

12. Further Reading

Keep Reading