#histogram #image

histogram_equalization

Histogram equalization

15 releases

0.2.4 Apr 16, 2025
0.2.3 Feb 18, 2025
0.2.2 Nov 10, 2024
0.2.1 Oct 13, 2024
0.1.5 Jun 23, 2024

#826 in Images

Download history 113/week @ 2025-12-23 14/week @ 2025-12-30 236/week @ 2026-01-06 69/week @ 2026-01-13 215/week @ 2026-01-20 435/week @ 2026-01-27 425/week @ 2026-02-03 250/week @ 2026-02-10 335/week @ 2026-02-17 776/week @ 2026-02-24 230/week @ 2026-03-03 296/week @ 2026-03-10 615/week @ 2026-03-17 375/week @ 2026-03-24 236/week @ 2026-03-31 309/week @ 2026-04-07

1,674 downloads per month

BSD-3-Clause OR Apache-2.0

125KB
3.5K SLoC

Histogram equalization in Rust

There is some implementation of CLAHE (contrast-limited adaptive histogram equalization), AHE (adaptive histogram equalization), and histogram equalization performed in different color spaces.

All methods may perform histogram equalization in:

  • YUV (YCgCo subtype) always with 256 hist bins for performance purposes.
  • HSV
  • HSL
  • CIE L*a*b
  • CIE L*u*v
  • Oklab
  • Jzazbz
  • Oklch

All color spaces as it is have different properties and of course results.

There is no implementation for gray images.

Example

clahe_luv_rgb(
    src_bytes,
    stride as u32,
    &mut dst_bytes,
    stride as u32,
    dimensions.0,
    dimensions.1,
    4f32,
    ClaheGridSize::new(8, 8),
    128,
);

How to use with image crate

let img = ImageReader::open("assets/asset_1.jpg")
    .unwrap()
    .decode()
    .unwrap();
let dimensions = img.dimensions();
let channels = 3;
let stride = dimensions.0 as usize * channels;
let mut dst_bytes: Vec<u8> = vec![0; stride * dimensions.1 as usize];
let src_bytes = img.as_bytes();
hist_equal_hsv_rgb(
    src_bytes,
    stride as u32,
    &mut dst_bytes,
    stride as u32,
    dimensions.0,
    dimensions.1,
    128,
);
image::save_buffer(
    "converted_eq_hsv.jpg",
    &dst_bytes,
    dimensions.0,
    dimensions.1,
    image::ExtendedColorType::Rgb8,
)
.unwrap();

Results example

Clahe

Original

CLAHE

Ahe

Original

Ahe


This project is licensed under either of

  • BSD-3-Clause License (see LICENSE)
  • Apache License, Version 2.0 (see LICENSE)

at your option.

Dependencies

~8.5MB
~174K SLoC