Image Enhancement
Overview
The enhancement module delivers a comprehensive suite of linear and non-linear radiometric transformation pipelines designed to optimize the visual quality, structural contrast, and dynamic range of satellite imagery. These processing steps adjust the distribution of digital numbers () across the available bit-depth spectrum, maximizing feature interpretability for human analysts or standardizing input spaces for downstream machine learning and deep learning computer vision architectures.
fezrs.base.BaseTool HistogramExportMixin
│ │
└─────────────┬─────────────┘
│
▼
┌───────────────────────────────────────┐
│ fezrs.tools.enhancement Module │
└───────────────────┬───────────────────┘
│
┌────────────────────────────────┴────────────────────────────────┐
▼ ▼
[Single-Band Processing Matrix] [Multi-Band RGB Processing Stacks]
├─ OriginalCalculator / FloatCalculator ├─ OriginalRGBCalculator
├─ EqualizeCalculator ├─ EqualizeRGBCalculator
├─ AdaptiveCalculator (CLAHE) ├─ AdaptiveRGBCalculator
├─ GammaCalculator └─ GammaRGBCalculator
├─ LogAdjustCalculator
└─ SigmoidAdjustCalculatorGlobal Radiometric Range Standardization
Before applying non-linear contrast alterations, input matrices must be converted from raw integer digital numbers () into a normalized, unitless floating-point domain.
Mathematical Quantization Normalization
Given an input integer raster channel exhibiting an arbitrary hardware bit-depth (e.g., 8-bit, 12-bit, or 16-bit engineering configurations), the linear standardization mapping resolves to:
This conversion maps raw raster matrices directly into a normalized floating-point range:
This transformation preserves the exact profile shape of the original data distribution while protecting downstream calculations from numerical overflow or underflow vulnerabilities.
Core Data Staging Interfaces
FloatCalculator
- Programmatic Purpose: Converts a single-band integer array to a normalized float format () of type
np.float64to establish a clean processing baseline.
OriginalCalculator & OriginalRGBCalculator
- Programmatic Purpose: Serve as unchanged reference baselines to evaluate the radiometric impact of active enhancement pipelines. For multi-spectral configurations,
OriginalRGBCalculatoringests individual visible channels and combines them along the third tensor dimension to yield a standard multi-band array layout:
Comprehensive Class Specifications
EqualizeCalculator & EqualizeRGBCalculator (Global Histogram Equalization)
Scientific and Physical Objective
Global histogram equalization maximizes global contrast across low-variance datasets (e.g., scenes flattened by heavy atmospheric haze or poor sensor exposure). It spreads out the most frequent intensity values, remapping the raw data profile into an idealized uniform probability distribution.
Theoretical Foundation & Mathematical Formulations
The mathematical transformation uses the continuous Cumulative Distribution Function (CDF) of the target image's grayscale values.
Let represent the normalized probability of an intensity level occurring within a discrete domain containing discrete levels (where for standard 8-bit distributions):
Where is the absolute count of pixels expressing intensity , and represents the global pixel count. The localized discrete cumulative probability function maps as:
The equalized intensity value is scaled directly to the normalized interval via:
In the underlying vectorized implementation handled by skimage.exposure.equalize_hist, this process evaluates sorted absolute ranks, replacing raw values with their normalized cumulative frequency:
Multi-Band Radiometric Behavior
EqualizeRGBCalculator runs this transformation across each channel independently. While this maximizes structural detail within each channel, it can distort the relative balance between channels, often causing unintended chromatic color-shifting artifacts across natural-color composites.
Interface Architecture
Constructor Inputs:
EqualizeCalculator:nir_path(str|Path)EqualizeRGBCalculator:red_path,green_path,blue_path(str|Path)
Return State: Returns a transformed 2D or 3D
numpy.ndarray(np.float64) mapped to a uniform output distribution.
from pathlib import Path
from fezrs.tools.enhancement import EqualizeCalculator
# Initialize global histogram equalization pipeline
equalizer = EqualizeCalculator(nir_path=Path("./data/Hazy_NIR.tif"))
equalizer.execute(output_path="./exports/enhanced/", title="Global Histogram Equalized")AdaptiveCalculator & AdaptiveRGBCalculator (CLAHE)
Scientific and Physical Objective
Contrast Limited Adaptive Histogram Equalisation (CLAHE) enhances local contrast within localized window tiles rather than modifying the global image histogram. This approach reveals fine structural details in both shadow and highlight regions simultaneously without amplifying background sensor noise.
Theoretical Foundation & Mathematical Formulations
The processing pipeline divides the 2D image matrix into a grid of non-overlapping contextual regions called tiles (typically matching an pixel block configuration).
For an arbitrary tile containing a spatial area of pixels across , the baseline uniform bin height evaluates to:
To prevent the amplification of high-frequency background noise in uniform areas, a user-defined clipping constraint () limits the height of any single bin:
Any structural data points that exceed this clipping threshold are clipped and redistributed evenly across all available histogram bins. The system then computes a localized cumulative distribution function () for that specific tile ():
Where is the clipped local histogram profile, and represents the total number of pixels in the tile following redistribution.
To eliminate blocking artifacts along tile boundaries, the final value for any pixel coordinate is computed using bilinear interpolation from the mapping functions () of the four nearest neighboring tiles:
Interface Architecture
Constructor Arguments (
AdaptiveCalculator):nir_path(str|Path): Target raster file location.clip_limit(float): Local contrast threshold limiter. Bounded between .
Constructor Arguments (
AdaptiveRGBCalculator):- Ingests individual
red_path,green_path, andblue_pathlayers while enforcing a hardcoded clip constraint of .
- Ingests individual
from pathlib import Path
from fezrs.tools.enhancement import AdaptiveCalculator
# Execute local adaptive contrast optimization via CLAHE
clahe_engine = AdaptiveCalculator(
nir_path=Path("./data/Variable_Lighting_NIR.tif"),
clip_limit=0.03
)
clahe_engine.execute(output_path="./exports/enhanced/", title="CLAHE Local Optimization")GammaCalculator & GammaRGBCalculator (Power-Law / Gamma Correction)
Scientific and Physical Objective
Gamma correction applies a non-linear power-law transformation to adjust image brightness. It can brighten shadow regions () or compress high-reflectance highlights () while anchoring the absolute dark and light endpoints ( and ).
Theoretical Foundation & Mathematical Formulations
The transformation scales pixel values using a non-linear exponential function:
Where:
represents the standardized input floating-point value in the range .
is an optional linear scaling factor (configured via
gain, defaulting to ).is the exponent that defines the shape of the correction curve.
Algorithmic Dynamics
: Maps as a strict linear identity function, leaving the data unchanged.
: Bends the response curve upward. This lifts mid-tones and stretches shadow details, making dark regions brighter while compressing highlights.
: Bends the curve downward. This darkens mid-tones, stretching highlight details while compressing shadows.
Interface Architecture
Constructor Arguments (
GammaCalculator):nir_path(str|Path)gamma(float): Default value set to .gain(int|float): Linear scaling factor, defaulting to .
from pathlib import Path
from fezrs.tools.enhancement import GammaCalculator
# Initialize power-law gamma transformation engine
gamma_corrector = GammaCalculator(
nir_path=Path("./data/Shadowed_Terrain.tif"),
gamma=0.45,
gain=1.0
)
gamma_corrector.execute(output_path="./exports/enhanced/", title="Power-Law Gamma Correction")LogAdjustCalculator (Logarithmic Compression)
Scientific and Physical Objective
The logarithmic transformation enhances structural detail within highly compressed shadow regions. It expands dark pixel values while compressing bright, high-reflectance highlights.
Theoretical Foundation & Mathematical Formulations
The forward transformation maps input intensities to a logarithmic curve via:
Where represents the user-defined linear gain factor. Because and , using a default gain of scales the output range to . To restore the full dynamic range to , the scaling factor must be rebalanced using a gain of .
When the inverse flag is set to True, the engine reverses this behavior by applying an exponential transformation:
This inverse mapping compresses shadow detail and expands variations in bright regions, making it ideal for highlighting features like clouds, snowcaps, or highly reflective mineral sands.
Interface Architecture
Constructor Arguments:
nir_path(str|Path)gain(float): Multiplicative scaler, defaulting to .inverse(bool): Determines whether to apply the forward log or inverse exponential curve.
SigmoidAdjustCalculator (Sigmoid Contrast Optimization)
Scientific and Physical Objective
SigmoidAdjustCalculator applies a logistic function to enhance contrast within a specific mid-range intensity band. It stretches the contrast of mid-tones while smoothly compressing extreme highlights and shadows, preserving subtle details at both ends of the spectrum.
Theoretical Foundation & Mathematical Formulations
The forward logistic transformation is defined mathematically as:
Where:
represents the
cutoffparameter, which determines the inflection point of the sigmoid curve along the intensity axis (set to by default). Pixels matching this intensity map exactly to the center of the output range ().represents the
gainparameter, controlling the slope and steepness of the curve. Higher gain values create a steeper transition, increasing contrast near the inflection point.
When the inverse flag is set to True, the transformation is inverted using the following function:
This inverse configuration stretches the extremes (highlights and shadows) while compressing contrast across mid-tone values.
Interface Architecture
Constructor Arguments:
nir_path(str|Path)gain(float): Sloping multiplier value (default: ).cutoff(float): Inflection point coordinate locator (default: ).inverse(bool): Toggle flag for inverse logistic transformation.
Telemetry Integration: The Histogram Export Subsystem
Except for LogAdjustCalculator, all classes within this enhancement module inherit from HistogramExportMixin. This component tracks radiometric changes across the processing pipeline by generating, formatting, and saving high-fidelity diagnostic histogram plots.
Telemetry Pipeline Features
Probability Density Profiling: Plots pixel intensity frequencies across bins to monitor radiometric shifts.
Automated Publication Watermarking: The mixin's internal
_add_watermark()method injects a professional FEZrs logo onto the plot layout, ensuring all exported figures are ready for inclusion in official technical reports or academic publications.
# Direct export example for radiometric distribution profiling
equalizer.histogram_export(
output_path="./exports/diagnostics/",
title="Radiometric Profile: Post Global Equalization",
figsize=(10, 6),
filename_prefix="equalized_band_5",
dpi=400
)Architectural Reference Summary
| Class Name | Optimization Profile | Mathematical Core | Key Downstream Use Case |
|---|---|---|---|
FloatCalculator | Linear Range Normalization | Standardizing integer imagery to float arrays before feature engineering. | |
EqualizeCalculator | Global Distribution Flattening | Enhancing contrast in low-variance images flattened by heavy atmospheric haze. | |
AdaptiveCalculator | Localized Adaptive Contrast (CLAHE) | Bilinear Interpolation over Grid Tiles | Enhancing structural details across scenes with high local variation or uneven lighting. |
GammaCalculator | Non-Linear Power-Law Adjustment | Brightening dark shadow regions () without blowing out pure highlights. | |
LogAdjustCalculator | Shadow Expansion / Highlight Compression | Mapping wide-dynamic-range sensor data to reveal low-intensity shadow details. | |
SigmoidAdjustCalculator | Mid-Tone Logistic Contrast Stretching | Enhancing local features by stretching contrast across mid-range intensities. |

