Expand description
Retinex image enhancement library
This library implements single-scale and multi-scale Retinex algorithms for image enhancement, with optional color restoration (MSRCR).
§Overview
Retinex separates an image into illumination (slowly varying lighting) and reflectance (object colors). The basic formula is:
I(x,y) = R(x,y) × L(x,y)Where I is the observed image, R is reflectance, and L is illumination.
§Algorithms
§Single-Scale Retinex (SSR)
Uses one Gaussian blur scale:
R = log(I) - log(G_σ * I)§Multi-Scale Retinex (MSR)
Averages multiple scales for better results:
R = Σ w_i [ log(I) - log(G_σi * I) ]§MSRCR (Multi-Scale Retinex with Color Restoration)
Applies color restoration to prevent grayscale output:
R_final = R_msr × (I_c / sum(I)) × 3§Example Usage
use retinex::{multi_scale_retinex_color_restored, single_scale_retinex};
// Single-scale (grayscale output)
let image = image::open("images/house.jpg").unwrap();
let result = single_scale_retinex(&image, 15.0).unwrap();
result.save("output.jpg").unwrap();
// Multi-scale with color restoration (recommended)
let result = multi_scale_retinex_color_restored(
&image,
&[15.0, 80.0, 250.0]
).unwrap();
result.save("color_output.jpg").unwrap();§Value Ranges
All processing is done in the [0, 1] range internally:
- Input images are converted to
Rgb32FImagewith values in [0, 1] - Illumination is stored in [0, 1]
- Reflectance is in log-domain (can be negative)
- Output is converted to 8-bit RGB [0, 255] only at export time
Structs§
- Retinex
Output - Output from Retinex processing containing both reflectance and illumination
Enums§
- Retinex
Error - Errors that can occur during Retinex processing
Functions§
- clamp_
reflectance - Clamp reflectance to physical constraint (reflectance ≤ 1.0 in linear space)
- extract_
illumination - Extract illumination at a specific scale
- multi_
scale_ retinex - Multi-scale Retinex (returns normalized 8-bit grayscale image)
- multi_
scale_ retinex_ color_ restored - Multi-scale Retinex with color restoration (MSRCR)
- multi_
scale_ retinex_ full - Multi-scale Retinex returning both reflectance and illumination components
- normalize_
per_ channel - Per-channel normalization (demonstrates the grayscale problem)
- normalize_
reflectance - Normalize log-domain reflectance for display using percentile clipping
- single_
scale_ retinex - Single-scale Retinex (returns normalized 8-bit grayscale image)
- single_
scale_ retinex_ color_ restored - Single-scale Retinex with color restoration (MSRCR)
- single_
scale_ retinex_ full - Single-scale Retinex returning both reflectance and illumination components
Type Aliases§
- Retinex
Result - Result type for Retinex operations