Skip to main content

Crate retinex

Crate retinex 

Source
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 Rgb32FImage with 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§

RetinexOutput
Output from Retinex processing containing both reflectance and illumination

Enums§

RetinexError
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§

RetinexResult
Result type for Retinex operations