| Crates.io | image-max-polling |
| lib.rs | image-max-polling |
| version | 0.1.2 |
| created_at | 2025-07-22 15:22:23.73387+00 |
| updated_at | 2025-09-12 03:13:14.487903+00 |
| description | A high-performance Rust library for maximum and minimum pooling operations on images, leveraging SIMD instructions (AVX2/NEON) and parallel processing for accelerated performance. |
| homepage | |
| repository | https://github.com/spartajet/image-max-pooling |
| max_upload_size | |
| id | 1763624 |
| size | 57,560 |
A high-performance Rust library for maximum and minimum pooling operations on images, leveraging SIMD instructions (AVX2/NEON) and parallel processing for accelerated performance.
image crate for input/outputAdd to your Cargo.toml:
[dependencies]
image-max-polling = "0.1"
Process an image with 8x8 max pooling:
use image_max_polling::{max_pooling_simd, supports_avx2};
use image::{GrayImage, ImageReader};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("AVX2 supported: {}", supports_avx2());
let img = ImageReader::open("input.png")?.decode()?.to_luma8();
let (new_width, new_height, pooled_data) = max_pooling_simd(
img.as_bytes(),
img.width() as usize,
8
);
let result = GrayImage::from_vec(
new_width as u32,
new_height as u32,
pooled_data,
).unwrap();
result.save("max_output.png")?;
Ok(())
}
Process an image with 8x8 min pooling:
use image_max_polling::{min_pooling_simd, supports_avx2};
use image::{GrayImage, ImageReader};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("AVX2 supported: {}", supports_avx2());
let img = ImageReader::open("input.png")?.decode()?.to_luma8();
let (new_width, new_height, pooled_data) = min_pooling_simd(
img.as_bytes(),
img.width() as usize,
8
);
let result = GrayImage::from_vec(
new_width as u32,
new_height as u32,
pooled_data,
).unwrap();
result.save("min_output.png")?;
Ok(())
}
Compare max and min pooling results:
use image_max_polling::{max_pooling_simd, min_pooling_simd};
let image_data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
let width = 3;
let factor = 3;
// Maximum pooling - extracts brightest features
let (_, _, max_result) = max_pooling_simd(&image_data, width, factor);
println!("Max pooling result: {:?}", max_result); // [9]
// Minimum pooling - extracts darkest features
let (_, _, min_result) = min_pooling_simd(&image_data, width, factor);
println!("Min pooling result: {:?}", min_result); // [1]
max_pooling_simd(input: &[u8], width: usize, factor: usize) -> (usize, usize, Vec<u8>)Performs maximum pooling operation using SIMD acceleration.
input: Input image data as a flat byte array (row-major order)width: Width of the input image in pixelsfactor: Pooling factor (e.g., 2 for 2x2 pooling)min_pooling_simd(input: &[u8], width: usize, factor: usize) -> (usize, usize, Vec<u8>)Performs minimum pooling operation using SIMD acceleration.
max_pooling_simdmax_pooling_simdsupports_avx2() -> boolChecks if the current CPU supports AVX2 instructions.
Both pooling operations are optimized with:
Typical performance on modern CPUs:
Run the provided examples:
# Basic max pooling
cargo run --example max_polling
# Basic min pooling
cargo run --example min_pooling
# Compare both operations
cargo run --example pooling_comparison
Run tests with:
cargo test
Run benchmarks with:
cargo test --release
MIT License - See LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.