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.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.
Video processing
- Capture video frames from a camera.
🛠️ Installation
>_ System dependencies
Dependeing on the features you want to use, you might need to install the following dependencies in your system:
turbojpeg
sudo apt-get install nasm
gstreamer
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
** Check the gstreamr installation guide: https://docs.rs/gstreamer/latest/gstreamer/#installation
🦀 Rust
Add the following to your Cargo.toml
:
[dependencies]
kornia-rs = { version = "0.1.2", features = ["gstreamer"] }
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_native(
&gray,
kornia_rs::image::ImageSize {
width: 128,
height: 128,
},
kornia_rs::resize::InterpolationMode::Bilinear,
)?;
println!("gray_resize: {:?}", gray_resize.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))
Resize an image using the kornia-rs
backend with SIMD acceleration
import kornia_rs as K
# load image with kornia-rs
img = K.read_image_jpeg("dog.jpeg")
# resize the image
resized_img = K.resize(img, (128, 128), interpolation="bilinear")
assert resized_img.shape == (128, 128, 3)
🧑💻 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 Distribution
Built Distributions
Hashes for kornia_rs-0.1.4-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89fdb85785aa4f447410ad7fb54380f72d882472a6d380051c33c796f8dece9b |
|
MD5 | b46a163e819f4c90b4734b495d3f3fd2 |
|
BLAKE2b-256 | c0e422ede143febf008663c33139f22dcf7ed02c7465e51cd3e8fb8c44f2715c |
Hashes for kornia_rs-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3279a499374090478a2519450ea7201f7fc23b5c2927ca20bca42e44da6ca23a |
|
MD5 | c08994be101a96f038962b2eb45aa4c2 |
|
BLAKE2b-256 | 3420a10d610c1a1c8f341cbc96dc5a7ccbc03a5e56ff5d7960febd3e11fcbd9e |
Hashes for kornia_rs-0.1.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3c9f80a34839f16c3a6942108834b9c7013c17b1d3ddea520a7f6a98f691c3b |
|
MD5 | 8235961947e44429aef6d4b274a4d287 |
|
BLAKE2b-256 | 88b9d209110901d8ae70e9006958074120f1382618955dc28e308381cfe51e9e |
Hashes for kornia_rs-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58f94d97df275a0cbedec52b5be2a808f0b76765d924aa854181a327726d5f30 |
|
MD5 | 597f16a75b0da8c2e8fdcc9353dd1f6c |
|
BLAKE2b-256 | b3a8146de87aa4a6e409fe05bad9785dc98e33b57eadbcb3658f09a35d9b860a |
Hashes for kornia_rs-0.1.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 824a0f4b68f6ba25c5d1cf195dd6a3f4f9892c295d12e05c30d10abc6ee04f7e |
|
MD5 | e834cc78bdfa1c5b5e3932ac4fcd0d16 |
|
BLAKE2b-256 | 1e4df84e31c1eee53a392cbb70e51b145567aff776a823ca54d69365a4530ebf |
Hashes for kornia_rs-0.1.4-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a47429d5a5fb6e8713011c3ae0e1f2f84027def81f54173b81faaae74587cd8 |
|
MD5 | cb1bbb08d1ed44893fd74932b69fd7e1 |
|
BLAKE2b-256 | c5ed4fe673652b1b42b1558ceaae70f5b32cc41d94b1f674abdd16be117b41f2 |
Hashes for kornia_rs-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b00b519ea9cfe7c604a47f81bcc2fadda99cff7a047a7de148a39362493d1b41 |
|
MD5 | 082a609638c554f68bf85c92cc59ebff |
|
BLAKE2b-256 | de84cec32ac7088edc064ba4f868bc135c325af578c40690324415bc85566235 |
Hashes for kornia_rs-0.1.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f190294ad34277c2133150785c344ed8e8e7b1b822107c016ce1d9bb3afd8ee9 |
|
MD5 | 553117e62db1e1d6ccd11c09281ce9db |
|
BLAKE2b-256 | 0c4360feeaacbbe034f4e9471ed508df272ef0a09030c4a7bf362d3102f766af |
Hashes for kornia_rs-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39117f96849bd0bdd15f4cb311a0812845aab712d36dff5d474bafc9e5fe33cc |
|
MD5 | d4625ce4d962584fcf392a47305788c7 |
|
BLAKE2b-256 | 593e19d8cd5f36ce3aa44da2a72b973349b2002f3a87d956aa11de3dd5cacad1 |
Hashes for kornia_rs-0.1.4-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3c6f7bfe600e47e63d9294907519641e86c2afb2b89995e6bf417c6f02aa9f0 |
|
MD5 | 5fe6c2291e52b75e3065aeea588974e9 |
|
BLAKE2b-256 | 0c06024e70e67423b3a718bfd96bcb72a7cda0d4a34f782230748f8066e9f3a9 |
Hashes for kornia_rs-0.1.4-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51954b02de368a3d437bfa4ca30944f930de95b9325f8576404744ff59fb0646 |
|
MD5 | 5aff39d429d3b3fbc03871a6d7617e61 |
|
BLAKE2b-256 | 695b52b4470e56ada67888ad2b8db00bf6bfd7da1ff7fc55ae6a74632babe079 |
Hashes for kornia_rs-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02444333e7c0e9a5d587261c147d202785cba0063217dbdcd003eb1b21d42162 |
|
MD5 | 05a7fb4e70696e7278376b48455d8a6b |
|
BLAKE2b-256 | 35f0ce1ee1cffa61657f6eb317a7d6dbe95cdbd990094d3dbe8d4ca522074955 |
Hashes for kornia_rs-0.1.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70fd23143763efa843eec99331106490c050c6525d23cf920610cf4faa2e36ca |
|
MD5 | c82857642d1564a46d11fed279c0d153 |
|
BLAKE2b-256 | 3fcf1e5600522faccd2510c30412e3457536033dccb001735b60ffe9f2812659 |
Hashes for kornia_rs-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e59752474f8e06d65cb7a155a1451037adf6e7c9067549a6e5c21d7b8739130c |
|
MD5 | c571d426197cf4db700b77be13fd323c |
|
BLAKE2b-256 | 90ee9450f349a48d1c7b7dd1b278bd8f417b3a152800ccf97658579373e34d51 |
Hashes for kornia_rs-0.1.4-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8c8afa6ef62a313097b45ad9fb3ba46131a404773fb87c48a6f1998ad77f729 |
|
MD5 | e9555508f74221e998dc3ff9d3aec8fb |
|
BLAKE2b-256 | 610b8174ad7d441674c8d85a9cf3891ab9295a58ca6da737f4f5596ee8e2735d |
Hashes for kornia_rs-0.1.4-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcccc6a4779944eadf736d800ac499e54391338aee028a8d3d3ff2cb391cc37e |
|
MD5 | c424636d581a217bb2d797f3f0faabc3 |
|
BLAKE2b-256 | 76623820e9b8ad60ebcb0d00ce80a54ba38386c3247191d47fa495882d984cc5 |
Hashes for kornia_rs-0.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 246785b038d8e77eeb742d6ea14faf4558ec22bed9b124b1c10f1929fac9a379 |
|
MD5 | 66e142954ff50e7082b7cc20bc048647 |
|
BLAKE2b-256 | a0d2375b7314db18bb169a1cca8ccb4ddd990739a32da09a1817c2f690885309 |
Hashes for kornia_rs-0.1.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7b18fe635901ce050b46611dce505bbec97ec497236a70fdc6959a66ffc4efb |
|
MD5 | daf6fa0a21293e63e883445c3bb47eeb |
|
BLAKE2b-256 | 15bd3ca36e1049f1367b6e28baa2f1d2839daba88541e622b28613723cf9f6e5 |
Hashes for kornia_rs-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db481fbd6a480335bf01e3be9b80fa81ad63f9261a7de21dc27247b3210db02a |
|
MD5 | ef0658574986697e0699386f68603328 |
|
BLAKE2b-256 | 1f0097c8d29365b94e0341206aad55d5ba2e10ba4ae616994125aaead8c992c8 |
Hashes for kornia_rs-0.1.4-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e07cedb7f65e9b37b974f293030b56d39a6d8985513e81f33fa57c26c38dac63 |
|
MD5 | 92da5fbedc6f81d1571ee824a29dda4f |
|
BLAKE2b-256 | 75acfaa88a4368b5f7aa000a032b8ede6d4b3ee74d1c4c794f3c0bf916965810 |
Hashes for kornia_rs-0.1.4-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ced35f6c0c85120fb0ea6a1b74ea6bff6b383facca24aa90e4e61cde73a58a9 |
|
MD5 | 0ac8eb84a965451b907c6c5f870de2fd |
|
BLAKE2b-256 | 70a218c4a8b4b632f7310e1a657762a8f34cad115286e3756d5b475b60d260e8 |
Hashes for kornia_rs-0.1.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f70fbd4c3bab901fccc9ec2ecd3e98e12703a9abc843e86edcb79961ef41440 |
|
MD5 | 8caea403136aad74e8851c1ca6ec0e6e |
|
BLAKE2b-256 | d6e2eae950b121eb41081b36fa3d7963208260f4475314153466e32b37c0d146 |
Hashes for kornia_rs-0.1.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fc8a0d9adc6c34f839d6f64f1746c7c2646a1f53eaeeff253df23e1d10443fd |
|
MD5 | ca60bceb26dc1600a749d1f9706d357f |
|
BLAKE2b-256 | 73a57d37b2888844c03f2bb9a955b93e07ab508ad439d3c878f76e01a2f9a6d1 |
Hashes for kornia_rs-0.1.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7a04760e0d59a7e953d8008f94fe1d061a033b0635b9eccf187847f04be0847 |
|
MD5 | 580dd219013a23a2c67f6adf8427666f |
|
BLAKE2b-256 | 31ce9422d22ca7a3b25f13c0d5985160740d1d90b39b939d5054c752109e759d |
Hashes for kornia_rs-0.1.4-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f45615ab2f5272c9f7d3e0f62ca3716c753baf7c1d3e3725f28bc452d9ac420 |
|
MD5 | aa8e1f3731162d3f7523bbac13ac2125 |
|
BLAKE2b-256 | 97240c0a63e427cfe8e74dbd65efe2acda0795b1884473f7a1ffb0b8fa8c3c49 |
Hashes for kornia_rs-0.1.4-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 035d21efd3e8fb6227d0f2655ab95ce484bbe7cc3c5a9dc1ef16b25a091d19dc |
|
MD5 | 741bfa0028fdada5cc61550606eee331 |
|
BLAKE2b-256 | 7e85a2fcacbe241b178f3406be3bfc5eeef002636f16a21ea0746174f800ff6a |
Hashes for kornia_rs-0.1.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c522acbcf02665ad6a64c799fcb19be90ced9881b7559487778455b4d80597 |
|
MD5 | 4fd9962da525ceb27d60b3a3613772b5 |
|
BLAKE2b-256 | a5c4159fd4dc105eab535581b9540fc629d16658f9bae1111ff544038f92dd01 |
Hashes for kornia_rs-0.1.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6017722c279919abe04586aaa3e4b115e2cae6f1698081f54e0a336443b2f6ba |
|
MD5 | 037ddd8aa1dd4fa823ebcf4171ef5e49 |
|
BLAKE2b-256 | e0112c567b95f60740e34291908585b3be883699bd82add19ca94b6b7762826e |
Hashes for kornia_rs-0.1.4-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fd89e89835f4b375138d2bb23c685a8ff1477919bdc3597275ce42e20aff06 |
|
MD5 | f5bd6ef5fa1b2f2635100450969686d8 |
|
BLAKE2b-256 | 2c99add2d4dd52f60dd03d365b2377747fb138c7a64425bedc61239d8b05390f |
Hashes for kornia_rs-0.1.4-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4931a063cfa71c6059976672ba7d81c4585286c28338f881b7146fc360d96622 |
|
MD5 | cf22990190d9da21cac52c67ee8b28fd |
|
BLAKE2b-256 | aaf48da2100337b8ea89e69bd6a4c7ad061c416b9b31faec14f401cbe112b9b2 |