Expand description
§Image Pyramid
§Overview
This is a small Rust crate that facilitates quickly generating an image pyramid from a user-provided image.
- See OpenCV: Image Pyramids for an overview of the two most common pyramid types, Lowpass (AKA Gaussian) and Bandpass (AKA Laplacian).
- The Tomasi paper Lowpass and Bandpass Pyramids has an authoritative explanation as well.
- Wikipedia has a decent explanation of a steerable pyramid
§Usage
See the crates.io page for installation instructions, then check out the examples directory for example code. Below is a simple illustrative example of computing a default pyramid (Gaussian where each level is half resolution).
use image::DynamicImage;
use image_pyramid::*;
let image = DynamicImage::new_rgba8(640, 480); // Or load from file
let pyramid = match ImagePyramid::create(&image, None) {
Ok(pyramid) => pyramid,
Err(e) => {
eprintln!("Error creating image pyramid: {}", e);
return;
}
};
Or a slightly more complex example, illustrating how to create a bandpass pyramid where each octave is 2/3 the resolution, smoothed using a triangle (linear) filter.
use image::DynamicImage;
use image_pyramid::*;
let image = DynamicImage::new_rgba8(640, 480); // Or load from file
let params = ImagePyramidParams {
scale_factor: (2.0 / 3.0).into_unit_interval().unwrap(),
pyramid_type: ImagePyramidType::Bandpass,
smoothing_type: SmoothingType::Triangle,
};
let pyramid = match ImagePyramid::create(&image, Some(¶ms)) {
Ok(pyramid) => pyramid,
Err(e) => {
eprintln!("Error creating image pyramid: {}", e);
return;
}
};
ImagePyramidParams::scale_factor
field is a UnitIntervalValue
, which
must be a floating-point value in the interval (0, 1). Creating a value of
this type yields a Result
and will contain an error if the value is not
valid.
§Support
Open an Issue with questions or bug reports, and feel free to open a PR with proposed changes.
§Contributing
Follow standard Rust conventions, and be sure to add tests for any new code added.
Structs§
- Image
Pyramid - A computed image pyramid and its associated metadata.
- Image
Pyramid Params - The set of parameters required for computing an image pyramid. For most applications, the default set of parameters is correct.
- Image
ToProcess - A simple wrapper extending the functionality of the given image with image-pyramid support
- Unit
Interval Value - A container for a value falling on the range (0.0, 1.0) (exclusive, meaning the values 0.0 and 1.0 are not valid)
Enums§
- Image
Pyramid Error - An enumeration of the errors that may be emitted from the
image_pyramid
crate - Image
Pyramid Type - What type of pyramid to compute. Each has different properties, applications, and computation cost.
- Smoothing
Type - How to smooth an image when downsampling
Traits§
- CanCompute
Pyramid - Describes types that can compute their own image pyramid
- Into
Unit Interval - A trait describing some floating-point type that can be converted to a unit-interval value (0.0 to 1.0, exclusive)