Low level implementations for computer vision in Rust
Project description
kornia-rs: low level computer vision library in Rust
The kornia-rs
crate is a low level library for Computer Vision written in Rust 🦀
Use the library to perform image I/O, visualisation and other low level operations in your machine learning and data-science projects in a thread-safe and efficient way.
Getting Started
cargo run --example hello_world
use kornia_rs::image::Image;
use kornia_rs::io::functional as F;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// read the image
let image_path = std::path::Path::new("tests/data/dog.jpeg");
let image: Image<u8, 3> = F::read_image_jpeg(image_path)?;
println!("Hello, world!");
println!("Loaded Image size: {:?}", image.image_size());
println!("\nGoodbyte!");
Ok(())
}
Hello, world!
Loaded Image size: ImageSize { width: 258, height: 195 }
Goodbyte!
Features
- 🦀The library is primarly written in Rust.
- 🚀 Multi-threaded and efficient image I/O, image processing and advanced computer vision operators.
- 🔢 The n-dimensional backend is based on the
ndarray
crate. - 🐍 Pthon bindings are created with PyO3/Maturin.
- 📦 We package with support for Linux [amd64/arm64], Macos and WIndows.
- Supported Python versions are 3.7/3.8/3.9/3.10/3.11
Supported image formats
- Read images from AVIF, BMP, DDS, Farbeld, GIF, HDR, ICO, JPEG (libjpeg-turbo), OpenEXR, PNG, PNM, TGA, TIFF, WebP.
Image processing
- Convert images to grayscale, resize, crop, rotate, flip, pad, normalize, denormalize, and other image processing operations.
🛠️ Installation
>_ System dependencies
You need to install the following dependencies in your system:
sudo apt-get install nasm
🦀 Rust
Add the following to your Cargo.toml
:
[dependencies]
kornia-rs = "0.1.0"
Alternatively, you can use the cargo
command to add the dependency:
cargo add kornia-rs
🐍 Python
pip install kornia-rs
Examples: Image processing
The following example shows how to read an image, convert it to grayscale and resize it. The image is then logged to a rerun
recording stream.
Checkout all the examples in the examples
directory to see more use cases.
use kornia_rs::image::Image;
use kornia_rs::io::functional as F;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// read the image
let image_path = std::path::Path::new("tests/data/dog.jpeg");
let image: Image<u8, 3> = F::read_image_jpeg(image_path)?;
let image_viz = image.clone();
let image_f32: Image<f32, 3> = image.cast_and_scale::<f32>(1.0 / 255.0)?;
// convert the image to grayscale
let gray: Image<f32, 1> = kornia_rs::color::gray_from_rgb(&image_f32)?;
let gray_resize: Image<f32, 1> = kornia_rs::resize::resize(
&gray,
kornia_rs::image::ImageSize {
width: 128,
height: 128,
},
kornia_rs::resize::ResizeOptions::default(),
)?;
println!("gray_resize: {:?}", gray_resize.image_size());
// create a Rerun recording stream
let rec = rerun::RecordingStreamBuilder::new("Kornia App").connect()?;
// log the images
let _ = rec.log("image", &rerun::Image::try_from(image_viz.data)?);
let _ = rec.log("gray", &rerun::Image::try_from(gray.data)?);
let _ = rec.log("gray_resize", &rerun::Image::try_from(gray_resize.data)?);
Ok(())
}
Python usage
Load an image, that is converted directly to a numpy array to ease the integration with other libraries.
import kornia_rs as K
import numpy as np
# load an image with using libjpeg-turbo
img: np.ndarray = K.read_image_jpeg("dog.jpeg")
# alternatively, load other formats
# img: np.ndarray = K.read_image_any("dog.png")
assert img.shape == (195, 258, 3)
# convert to dlpack to import to torch
img_t = torch.from_dlpack(img)
assert img_t.shape == (195, 258, 3)
Write an image to disk
import kornia_rs as K
import numpy as np
# load an image with using libjpeg-turbo
img: np.ndarray = K.read_image_jpeg("dog.jpeg")
# write the image to disk
K.write_image_jpeg("dog_copy.jpeg", img)
Encode or decode image streams using the turbojpeg
backend
import kornia_rs as K
# load image with kornia-rs
img = K.read_image_jpeg("dog.jpeg")
# encode the image with jpeg
image_encoder = K.ImageEncoder()
image_encoder.set_quality(95) # set the encoding quality
# get the encoded stream
img_encoded: list[int] = image_encoder.encode(img)
# decode back the image
image_decoder = K.ImageDecoder()
decoded_img: np.ndarray = image_decoder.decode(bytes(image_encoded))
🧑💻 Development
Pre-requisites: install rust
and python3
in your system.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Clone the repository in your local directory
git clone https://github.com/kornia/kornia-rs.git
🦀 Rust
Compile the project and run the tests
cargo test
For specific tests, you can run the following command:
cargo test image
🐍 Python
To build the Python wheels, we use the maturin
package. Use the following command to build the wheels:
make build-python
To run the tests, use the following command:
make test-python
💜 Contributing
This is a child project of Kornia. Join the community to get in touch with us, or just sponsor the project: https://opencollective.com/kornia
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for kornia_rs-0.1.0-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4657e4b2d7652cb9e286882301efa72f089b490e56bf3393edabed68e97befff |
|
MD5 | 5387b3b81971682e4052ed7c674ff2d2 |
|
BLAKE2b-256 | 0d2104516de6a4a5b6c5e5ccf47d2eb3968c9462b6477b06d6da3564d7731da0 |
Hashes for kornia_rs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ded4a67777f4a9325d9fce0bd041fc0bff451fd556a5e1f7183b87ba97f1021 |
|
MD5 | d565f4a7210b346f126a068e2c939565 |
|
BLAKE2b-256 | f29025bbe13f2465fe156341ba482854943f59b9d0076551bf0818e0902aa90b |
Hashes for kornia_rs-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b1e2976f787fa468f76b607a5b4bf5761bad2ac279274657bedf18b23d6ea5b |
|
MD5 | efd9ceb5fb1adf4204e9455bc292a0db |
|
BLAKE2b-256 | 4f1c01c7ff2a805669c7ae3c756de2f53e132ad359f42b0eb520453aedbd3ef4 |
Hashes for kornia_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4244259149eb5183690c9d37dd568b459e84332797a3561569623ca7af4c8dca |
|
MD5 | 4a8c6006b06ed86c78df0e7e2834f9b5 |
|
BLAKE2b-256 | c7db43d9b6b82262ac2fe55e6b3f8052658beb49ec1dd05a00664d1c6d7cbcec |
Hashes for kornia_rs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6d755464268f88ff4597af8e7a49cdadd15136de0ac45c7fde914f9b5a428ac |
|
MD5 | 2e8b591db421cf745822ce0361e8f916 |
|
BLAKE2b-256 | db25842aacdc22cb3c081ad8b7bc0b0d28806bfd24227b607c7d0757b5ab6977 |
Hashes for kornia_rs-0.1.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4878231f56cb38eb7918c868a25326b1b3fe8b828beed3edd0195d9a915a6920 |
|
MD5 | 83a716a826bb28de6faa87da700e0dc2 |
|
BLAKE2b-256 | d57cc66082918a2b57f5c631671379099726dcdf32cb375b8e458ac17e0a6ac7 |
Hashes for kornia_rs-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 562db13a553d49de068b9166d3037c63f94d31028d1e7681ce0def67d42a385c |
|
MD5 | 88f45727331d41deba5764a9e2bdd012 |
|
BLAKE2b-256 | 9ef00c492117ddb3408b8b827ca6871a0d14c99c8a3f7275f593a367c910aaaa |
Hashes for kornia_rs-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efa4d9b8e60d08b2f05545bba226e6d7cbcfccd9381eccc697503dbfd9b5fabd |
|
MD5 | eb8b6ce398cf017749a48e235fc50a05 |
|
BLAKE2b-256 | 6a47ce0bb2ece639845bacd508d21dea6c0a31dc1d53135b4baad2ca34fbf46a |
Hashes for kornia_rs-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c88632412d35d18625055d4234ffd35bf87c61078bebbfd19080e2aedce12454 |
|
MD5 | 273af55d509599517f726b7998d66510 |
|
BLAKE2b-256 | 9abf17c55bac34b93c5b2bcd10986bc26a543d1e9ce1ed1104a695e0e3aac08c |
Hashes for kornia_rs-0.1.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 181e5b69d9435e83530e284a2d9650aa204d5219e12a4a409c14ea9d1efdde48 |
|
MD5 | 2c3abf9b3f3ab64bc4eb6a1092bb9db8 |
|
BLAKE2b-256 | 691b8bb5ba887cfae1770a9b4f28f1ac33c2160e43526a3d27796162df851d29 |
Hashes for kornia_rs-0.1.0-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd1a35f1fbe1d51244fe5ba46a2d0bfa07445ecef76cf91abfe09f8de1018922 |
|
MD5 | dd9e3e226c22745407dd54b4906f4bf8 |
|
BLAKE2b-256 | 442deccbac39b4669924d4f551384f1ea6225070dac4b9c4cd4007d34e60f88b |
Hashes for kornia_rs-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffc956e737e0d71ca2a9f72a1d742f418c71e3b357865e07d48da34219aa5b61 |
|
MD5 | 217a71c116fb49cf720c3f1ee535ba89 |
|
BLAKE2b-256 | 54856448fd567ac0a580e25a1941d6064479ccb78edf0750e23e7ab383c7f837 |
Hashes for kornia_rs-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8c16dd793caccc1fc62625253d4d84b79e94985f2fb434f38217ee1f10c2183 |
|
MD5 | b6550e1ed0e28e11f2ada66b4f8902eb |
|
BLAKE2b-256 | a32e0d614839e81094cdde91b84ee30f1b8bdd2d62a1bc55d468af7b9ba80f68 |
Hashes for kornia_rs-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1440c9eaff233a3fe0455d1e8326ee6fe030e402254a057716b92ecaeaca35a |
|
MD5 | c4fd32b786a14c3604ea0c52dd1d73c7 |
|
BLAKE2b-256 | 6631817bd83ceba941a89b4ff4ba99914c5b69c42c11fc6d139dc0f2f01b0a86 |
Hashes for kornia_rs-0.1.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dbba8302e47fb9b5f5fcacc4a8afbeb67f771962c0ab3b477c01609fb66b754 |
|
MD5 | 841a8e37ef80d63cfd04b3c3c15aa920 |
|
BLAKE2b-256 | 310486aaef80d66d123f7448ada3d8a553287bf9d28066987d0e526e3a1cf822 |
Hashes for kornia_rs-0.1.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bc230b731afcb4ed03e22c86b277e533d25e8d4299eb28683a4d5fd23be0d2c |
|
MD5 | 4c2a713f8aa97d26c1d2fcb24fbd13cd |
|
BLAKE2b-256 | 3c60737762f2f0bd320b3d20b451770a5cbfc65233c925aa68f809d518f14646 |
Hashes for kornia_rs-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b660f8b0d495d45d3557b80149dd65ead7103858748133114df243a8f936f0b |
|
MD5 | 98770fa3c539ca9f50d72f1dd58b1499 |
|
BLAKE2b-256 | 115143f258ff0c620a7de86725c4c0c43591c7be1193c9d5a461b01347aeb2d9 |
Hashes for kornia_rs-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b9cff60df50a21fd9449ce1654a7fc3c31c85be97b31974ccbd73c53009192c |
|
MD5 | 246e553ddab58de93ba0be31b83599fe |
|
BLAKE2b-256 | deb7c2e82dcad53b84c7953f74a1094ecae53722db012eaea977a7f34695b89a |
Hashes for kornia_rs-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bbcc49b75ef2ba934d476d41b361746ddad1a143627e0fa92832a010719b9c9 |
|
MD5 | d923b2eaed09db6369e748e22f2b161b |
|
BLAKE2b-256 | 577add9ff2423ead272f13eaf7927c2af60a3dc0c94e74428af335d361c8d9fd |
Hashes for kornia_rs-0.1.0-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30f1d6bd423033942723cb77b289ee80ab413616db96e046591af2faab39d1fc |
|
MD5 | 7af77d1641c0df002fc667ed430691a3 |
|
BLAKE2b-256 | 2c0e0b1897a920297f18f01e308f2db1be4447ff9976a3f612ea07171f42d8c3 |
Hashes for kornia_rs-0.1.0-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abba3aaa8645ceeb7640311fcff3b48ff25514cb153733eec018381654334ab1 |
|
MD5 | 85425f3362395574c123ab49f31ab427 |
|
BLAKE2b-256 | b50923660260460d811ea2aa07f33ca2654f1f4a673ccd939deed293e60bee9c |
Hashes for kornia_rs-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4614cb642cc1e100d45f6c63e1491488c476f27feaf33219970e381ece273c73 |
|
MD5 | 4e9701d8e456c7cb7ca296f22675fc85 |
|
BLAKE2b-256 | 644b2e7f081bf60ede439b67b756396f0fe783abac3be4eede987da2726585dc |
Hashes for kornia_rs-0.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 108c4335080826b07f9d875dc39114558dbbc3253bf6a6cae24f37c592d8296d |
|
MD5 | 1f6f27da75dee464132f11047e4a0985 |
|
BLAKE2b-256 | 32772f587c3af062b76765e0f3a23cfc5c4e8e37e2a71b2b7b4c40ba97fba243 |
Hashes for kornia_rs-0.1.0-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e783317006227a34fb32dd88edea09aecff82eee1ff5330aa4e4fcc64d26cc0 |
|
MD5 | 175a39f0ab5943475f91f449e9c92488 |
|
BLAKE2b-256 | 5f06597f05da455be5ec2268704a9cdf915d1851f610ab5ce15596c07c90bb12 |
Hashes for kornia_rs-0.1.0-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4089064d4d3b5fe968f5b31d86b965f7418a1857408449990292aaa54d8634e1 |
|
MD5 | 25bba0ed461df6b559d545a700e0b7f2 |
|
BLAKE2b-256 | 7b3d4917ac0f8a87e2e8f5069c0a8b67cd3f1d52233aadba42a54be8d102d00b |