8 releases
| 0.1.10 | Nov 8, 2025 |
|---|---|
| 0.1.10-rc.3 | Jul 1, 2025 |
| 0.1.9 | May 7, 2025 |
| 0.1.9-rc.1 | Feb 16, 2025 |
| 0.1.6-rc.5 | Sep 19, 2024 |
#295 in Images
8,252 downloads per month
Used in 9 crates
(5 directly)
110KB
2K
SLoC
Kornia: kornia-image
Image types and traits for computer vision in Rust.
🚀 Overview
kornia-image provides a strongly-typed image representation for computer vision applications. It is built on top of kornia-tensor and offers a flexible memory layout that supports various pixel formats and data types. The library is designed to be zero-copy where possible and allows for easy integration with other libraries in the ecosystem.
🔑 Key Features
- Strongly-typed Image Struct: The
Image<T, C, A>struct ensures compile-time safety for pixel types (T) and channel counts (C). - Flexible Memory Management: Uses the
ImageAllocatortrait to support different memory backends (e.g., CPU, potentially GPU). - Rich Operations: built-in support for casting, scaling, channel splitting/merging, and pixel access.
- Arrow Integration: Optional support for converting images to Arrow format for data processing pipelines.
- Color Space Safety: Includes typed wrappers for color spaces (e.g.,
Rgb8,Gray8) to prevent mixing up image formats.
📦 Installation
Add the following to your Cargo.toml:
[dependencies]
kornia-image = "0.1.0"
🛠️ Usage
Here is a simple example showing how to create and manipulate an image:
use kornia_image::{Image, ImageSize, allocator::CpuAllocator};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Create a dummy RGB image (3 channels) with u8 data
let image_size = ImageSize { width: 10, height: 20 };
let data = vec![0u8; 10 * 20 * 3];
let image = Image::<u8, 3, _>::new(image_size, data, CpuAllocator)?;
println!("Image size: {:?}", image.size());
println!("Channels: {}", image.num_channels());
// 2. Cast to f32 and scale values to [0, 1]
let image_f32 = image.cast_and_scale::<f32>(1.0 / 255.0)?;
// 3. Access specific pixel (slow, for convenience)
let pixel_val = image_f32.get_pixel(5, 5, 0)?;
println!("Pixel at (5,5) ch 0: {}", pixel_val);
// 4. Split into individual channels
let channels = image_f32.split_channels()?;
println!("Split into {} single-channel images", channels.len());
Ok(())
}
🧩 Modules
image: CoreImagestruct,ImageSize,ImageLayout, andPixelFormat.allocator: Memory management utilities and theImageAllocatortrait.error: Error types for the image module.ops: Basic image operations.color_spaces: Typed wrappers for common color spaces.arrow: (Optional, feature:arrow) Utilities for Apache Arrow integration.
💡 Related Examples
You can find comprehensive examples in the examples folder of the repository:
image_api: Demonstration of the basic image API.color_spaces: Working with different color spaces.foxglove: Using image types for visualization.ros-z-nodes: Using images in a ROS 2 context.
🤝 Contributing
Contributions are welcome! This crate is part of the Kornia workspace. Please refer to the main repository for contribution guidelines.
📄 License
This crate is licensed under the Apache-2.0 License.
Dependencies
~0.2–3.5MB
~64K SLoC