Crates.io | color_reducer |
lib.rs | color_reducer |
version | |
source | src |
created_at | 2024-12-11 09:11:33.495141 |
updated_at | 2024-12-11 13:56:37.542334 |
description | Simplify images by reducing the number of colors based on a predefined palette. |
homepage | https://github.com/AllenDang/color_reducer |
repository | https://github.com/AllenDang/color_reducer |
max_upload_size | |
id | 1479815 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Welcome to the Color Reducer library! This Rust crate provides functionality to simplify images by reducing the number of colors based on a predefined palette. It is particularly useful for image processing tasks where color quantization and noise reduction are required.
The Color Reducer library allows you to reduce the number of colors in an image by mapping each pixel to the closest color in a predefined palette. Additionally, it offers functionality to merge small regions (considered as noise) into larger ones based on an area threshold, enhancing image quality by removing insignificant details.
Add this crate to your project:
cargo add color_reducer
Then, run cargo build
to fetch the library.
Here's a simple example of how to use the Color Reducer library to process an image:
use image::DynamicImage;
use color_reducer::ColorReducer;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load an image from a file path
let img = image::open("input_image.png")?;
// Define your palette of colors (as RGB arrays)
let palette = vec![
[255, 255, 255], // White
[0, 0, 0], // Black
[255, 0, 0], // Red
// Add more colors as needed
];
// Create a new ColorReducer instance
let reducer = ColorReducer::new(palette);
// Process the image
let reduced_img = reducer.reduce(&img)?;
// Save the processed image to a file
reduced_img.save("output_image.png")?;
Ok(())
}
Use following white-to-black 16 color palette
let palette = vec![
[255, 255, 255],
[238, 238, 238],
[221, 221, 221],
[204, 204, 204],
[187, 187, 187],
[170, 170, 170],
[153, 153, 153],
[136, 136, 136],
[119, 119, 119],
[102, 102, 102],
[85, 85, 85],
[68, 68, 68],
[51, 51, 51],
[34, 34, 34],
[17, 17, 17],
[0, 0, 0],
];
you will get
This project is licensed under the MIT License and APACHE License. See the LICENSE file for details.
Thank you for choosing the Color Reducer library! We hope it meets your image processing needs. If you encounter any issues or have any questions, please feel free to reach out via the issue tracker on GitHub.