A Rust library and CLI for generating blue noise textures and dithering images using the void-and-cluster algorithm.
cargo install blue-noiseOr build from source:
git clone https://github.com/mblode/blue-noise.git
cd blue-noise
cargo build --releaseblue-noise generate --size 128 --output blue-noise.pngOptions:
--size- Texture size in pixels (default: 128)--output- Output file path--sigma- Gaussian sigma, 1.0-3.0 (default: 1.9)--seed- Random seed for reproducibility--verbose- Show progress
blue-noise dither -i input.jpg -o output.pngOptions:
--input- Input image--output- Output image--noise- Blue noise texture (default: blue-noise.png)--foreground- Foreground color as hex (default: #000000)--background- Background color as hex (default: #ffffff)--width- Output width--height- Output height--contrast- Contrast adjustment (default: 1.0)
Add to your Cargo.toml:
[dependencies]
blue-noise = "0.2"Generate a texture:
use blue_noise::{BlueNoiseGenerator, BlueNoiseConfig, save_blue_noise_to_png};
let config = BlueNoiseConfig {
width: 128,
height: 128,
sigma: 1.9,
seed: Some(42),
..Default::default()
};
let generator = BlueNoiseGenerator::new(config)?;
let result = generator.generate()?;
save_blue_noise_to_png(&result, "blue-noise.png")?;Apply dithering:
use blue_noise::{BlueNoiseTexture, Color, DitherOptions, apply_dithering};
let noise = BlueNoiseTexture::load("blue-noise.png")?;
let options = DitherOptions {
foreground: Color::from_hex("#000000")?,
background: Color::from_hex("#ffffff")?,
width: Some(800),
height: None,
contrast: Some(1.2),
};
apply_dithering("input.jpg", "output.png", &noise, options)?;- Ulichney, R. (1993). "Void-and-cluster method for dither array generation"
- Ulichney, R. (1988). "Dithering with blue noise"
MIT



