Crate pixelization

Crate pixelization 

Source
Expand description

§Pixelization

pixelization is an image quantization and pixelization library. It implements standard strategies like K-Means Clustering and complex, structure-aware strategies like Pixelated Image Abstraction (PIA).

§Examples

§Basic K-Means

Fast and simple color reduction.

use pixelization::{KmeansPixelizer, Pixelizer, ColorType};

let img = image::open("input.png").unwrap();
let pixelizer = KmeansPixelizer::new(3, 20, ColorType::Lab);
 
// Downscale to 64x64 and reduce to 8 colors
let result = pixelizer.pixelize(&img, 64, 64, 8).unwrap();
result.save("output_kmeans.png").unwrap();

§Pixelated Image Abstraction (PIA)

Structure-aware pixelization using the default parameters from the original paper that you can find at https://pixl.cs.princeton.edu/pubs/Gerstner_2012_PIA/index.php.

use pixelization::{PIAPixelizer, Pixelizer};
 
let img = image::open("input.png").unwrap();
 
// Use default parameters (m=45.0, alpha=0.7, etc.)
// This is recommended for most images.
let mut pixelizer = PIAPixelizer::default();
 
// Optional: Enable verbose logging to see iteration progress
pixelizer.set_verbose(true);
 
// PIA is computationally intensive; small target sizes (e.g., 64x64) are recommended.
let result = pixelizer.pixelize(&img, 64, 64, 8).unwrap();
result.save("output_pia.png").unwrap();

Structs§

KmeansPixelizer
A Pixelizer that uses K-Means clustering to find the dominant color palette.
PIAPixelizer
A Pixelizer that relies on Pixelated Image Abstraction (PIA).

Enums§

ColorType
The color space used for calculating distances between colors for K-means pixelization.
CropMethod
Defines how the image should be cropped when scaling.
PixelizationError
Errors that can occur during the pixelization process.

Traits§

Pixelizer
The main trait for any pixelization algorithm.

Functions§

scale_to_size
Helper function to scale an image to a specific size with cropping options. Returns the new image and the effective dimensions.