#computer-vision #image-processing #pixel #traits #kornia #vision-image #3d

kornia-image

Image types and traits for generating and manipulating images

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

Download history 760/week @ 2025-11-30 969/week @ 2025-12-07 791/week @ 2025-12-14 513/week @ 2025-12-21 514/week @ 2025-12-28 1210/week @ 2026-01-04 1863/week @ 2026-01-11 2248/week @ 2026-01-18 1643/week @ 2026-01-25 1213/week @ 2026-02-01 1337/week @ 2026-02-08 721/week @ 2026-02-15 1743/week @ 2026-02-22 2356/week @ 2026-03-01 2203/week @ 2026-03-08 1802/week @ 2026-03-15

8,252 downloads per month
Used in 9 crates (5 directly)

Apache-2.0

110KB
2K SLoC

Kornia: kornia-image

Crates.io Documentation License

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 ImageAllocator trait 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: Core Image struct, ImageSize, ImageLayout, and PixelFormat.
  • allocator: Memory management utilities and the ImageAllocator trait.
  • 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.

You can find comprehensive examples in the examples folder of the repository:

🤝 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