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.1-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f10013068bb94118fe1146f449748a91c8490558bb9a3ade46deaa04b88f2c62 |
|
MD5 | af23915286a4a20cdd7e6c0052563575 |
|
BLAKE2b-256 | 4a995e131a5a74b5987c3eff44381f995a25ec491a37551fa9cb75fa7fb1d200 |
Hashes for kornia_rs-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8a4847929aa2422373394d42e5e247bc49995aca50520660942d506450779da |
|
MD5 | 5324bc11a5361a33d8ce01898b1adf5d |
|
BLAKE2b-256 | 2d9ee3918262858eb560f23dd2401df86eeaa55e7c110f75155d74e8f131e522 |
Hashes for kornia_rs-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66567d3cc31214f811f2550db12aa9ab38fb7e624534c29fd910830c78c60b95 |
|
MD5 | 9851fc0d7bd098c4ad9b430bc055d956 |
|
BLAKE2b-256 | 4c6226f1912471db9851f9d1926ec1ce34cc83dceef7d42aef88d01e0d78475a |
Hashes for kornia_rs-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f94c5b70c034da0d5608809c669c8e78177bddbf20b3d49c70f7e005b8243b33 |
|
MD5 | 65039b11246cc28bf253bb825647e07c |
|
BLAKE2b-256 | c4ac44c1a6cfd4183cc2d7b5884d2d175b2f8b54e66fcbd8c863e360602801cd |
Hashes for kornia_rs-0.1.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 198c57e918a9810be2fe515a0403f87b6d290b4a040faeedc7fc01212dbfec31 |
|
MD5 | 4dd6e8af70ee13d36f8dedd002816f21 |
|
BLAKE2b-256 | a457d0b8dc17f15a4a05da0b767cb99cbfc9b18cafdcad912a13ab4921f2601e |
Hashes for kornia_rs-0.1.1-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04efe54b812910ec964a0e9134276021c3253502e068b18493c4c211e3485d83 |
|
MD5 | 06b22fb1c5e50bad34f84aeca0310294 |
|
BLAKE2b-256 | afaa41205cc7991891d98f0ad77a2b5a97c02a967bb399772fe006a0205846e8 |
Hashes for kornia_rs-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b98d92892bf4cb03c219bcd9f5c8edd6906411dfc977e8258228d8558324f399 |
|
MD5 | 32a26b44dfbe5893d90074488fe0d194 |
|
BLAKE2b-256 | 7ca4cc806ba519e189518fe874a0ea43ce2b4b71c1709f6e865a15fe92507dc5 |
Hashes for kornia_rs-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88049237773fd2d0a6612f2cad2eececb60f7e0f8813dd8bcde0c0ea0f504218 |
|
MD5 | ab70d55c373c902f934c53822b2e8597 |
|
BLAKE2b-256 | 4fbfbc8ef7564b8d0a280e941da07d82082adc5bb16e9bd7c52db6106d8c2614 |
Hashes for kornia_rs-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c72ef63b592c2caa5bc7d8e835c4bfcb083468b4bcb49c333628c9cd865055f |
|
MD5 | 093fc6aade11ebc5123c30799441e8db |
|
BLAKE2b-256 | 138f17e336df6aea6719e6367e72d2af267b54ad90926aa1c6d505a1b3eaa760 |
Hashes for kornia_rs-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 546cdc587611308b8cad4faf2daaed401c2ee2fc52f25248786d192ba0389dc2 |
|
MD5 | a6c4c7f13294f041ba6b688d3a6eb765 |
|
BLAKE2b-256 | 9daa8b4e1dd41b9caf00f93d8c04e256936a2a2a3f2a686d4a3bff48509f3adb |
Hashes for kornia_rs-0.1.1-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ec2b6b8c0f937efe660900e57eeae6dfa33e7f421bac91174617e65f1de115b |
|
MD5 | 94f7c3587aaf84b2ff4d4b3f2a1c853c |
|
BLAKE2b-256 | 202e89d320c0db714ee154c0ca4911fa974b9e371840af798e0a810b1b09b8ed |
Hashes for kornia_rs-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88a8a99e19aa2864384eff0a196392fe797e791103eb10c48a6424d92816e330 |
|
MD5 | 5fa6b50bb22eaac8d198aa5c98d4027a |
|
BLAKE2b-256 | f30e29cd86fbd0d7e6d4562e7eec2301a818050bc371b05b54c10e94f4062d22 |
Hashes for kornia_rs-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85c9ce62acbf7ff8a5f59f7029b148ae9bd4fdef21a3e739d7a02c55051e9d8e |
|
MD5 | 31a3e10ac3a4996a76f0ced0b8c803bb |
|
BLAKE2b-256 | 99f21cb8a4c3043e1e3ae6c606dd519b9cc20c6356d093ebb45e06ebc4157f92 |
Hashes for kornia_rs-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91c5f372e77fe13453ff92d034d228f5e2efb6de3b04e8cd582cd3e3bdef7878 |
|
MD5 | f4d436b3639a9bec8ba9920ac345e3ef |
|
BLAKE2b-256 | 218e93cf117f0d8de2696fdbb68c6f11d0019f5dc08188ab678a1d45eb695079 |
Hashes for kornia_rs-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b20a7db11c68096d34afc363bf62727eda614c0444e448848c38db2dcdaa59af |
|
MD5 | 0905b75bc09ac33df8a86e1b06677f35 |
|
BLAKE2b-256 | 497be590498c20a10ac9930dbd01bb945dfa991642c76cde382998e2d6ef048c |
Hashes for kornia_rs-0.1.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82a592c3d5ddbe874fc615f1cbff49f344c1c7a1d7294d64f34aee64e51db533 |
|
MD5 | 7b1666b955d53bd276c6c9f2ab8f6b35 |
|
BLAKE2b-256 | 354c68534703ece1a036b1a07854da13dc55b6971397439abe0c3f7db1a26046 |
Hashes for kornia_rs-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d222268dc6acfb2095456282203e388eb60897ef7d071c8572feb3eadbe495f |
|
MD5 | 1c191509112a5ac60acc5d8efe2a990a |
|
BLAKE2b-256 | 1f203e76c89a681996ca65d392b56b2d410f1c319d5f816c01716f64d8c76a1c |
Hashes for kornia_rs-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 856ed4074b463ab0ed000260b65003f251f7781561b64ce58974516236950e5d |
|
MD5 | ab9ca1a1a1c335c0e8d93a20956433d4 |
|
BLAKE2b-256 | 4de6f998351493867fb55fb29586c46e9efdd39503fea668587626dad890c086 |
Hashes for kornia_rs-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8f1f276e047c6c2ef1c10f34ef5c86be2e72ee6932300c31208dff16608c569 |
|
MD5 | d3c544a30e813b0043e61b27e56f210d |
|
BLAKE2b-256 | 472b26bd0f6981bdae33489fa88cc3f3ebd09ae529dee3c5da474729d1d2771d |
Hashes for kornia_rs-0.1.1-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20857a25a34b70f82183951c242c2fc044eea21f1f4fcc84b5b9b4c14dded2e8 |
|
MD5 | a39aaaff4ddcf6cc394add58c963c2f2 |
|
BLAKE2b-256 | fc8140bc83de6639518e9aed739a41292bb8cf5bb811b6746730c4c6ded1b6d8 |
Hashes for kornia_rs-0.1.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ef6e216b41302356e10e791da3d617f45198cc4bd7f5019d3119ed1245eb8c2 |
|
MD5 | 68f3c5b83300ba647f685410bf247565 |
|
BLAKE2b-256 | 5b12b573389201b0987a0c2d90c30e5b52aff04de9adf4f397bf0e36d5c897b0 |
Hashes for kornia_rs-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f32f0b94cda5b269bfe44393d02752fd70bcd863101ef4b034c81c15d0b9119d |
|
MD5 | 97157e0dae3a128abe88cee54a71d7d2 |
|
BLAKE2b-256 | ea2454523c5cda3cfc0aafccabafbf1eddc4b2053b4369e32341d2a3c82e0e2b |
Hashes for kornia_rs-0.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bde13c75b9859760f8968c02d910e4d1cb1305addf60fe46580128a6de98feab |
|
MD5 | 144747ec4d8cefb496154c57e383c42c |
|
BLAKE2b-256 | 77e2d9c18d21d8ede4cccb9c5e0d558c4758f98a723be0afe7318ed0359dd458 |
Hashes for kornia_rs-0.1.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67153beded95e01df28662cb8bc3a30ccafb3e3a7e700d941bb2857211f3b773 |
|
MD5 | 5a487a3fabf1d767d9a597d9572e6028 |
|
BLAKE2b-256 | 5f1497f7ede8fa95a2e94c099975b2abf6873432c4f52a82d492913d02e62c80 |
Hashes for kornia_rs-0.1.1-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac63651d0233ebef1f308395e22b92e7c670cb55ae2e4e76f8242ed2d368c477 |
|
MD5 | 26d736984b12e2bbb6ffa60c5c30c18d |
|
BLAKE2b-256 | fadf921ac06ef2f4c7b213c05429c0b928fd1a0779758756fbf0fb2611d9b049 |
Hashes for kornia_rs-0.1.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd04a48d4b170b6a448d323704f302e4569c494787cd62b57e6f06bfba63c739 |
|
MD5 | 04973f5356efdd06a8888e46a7a77d41 |
|
BLAKE2b-256 | cf745e3c8533ccbc725e70c2b59f9dfdfce2ec6fd6974d2ffaa3b02bbf19299b |
Hashes for kornia_rs-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 528d3660bb503e452da02bc5441020d5f1cb24a552693c7013302db48f24969e |
|
MD5 | d6d571c1aae161af0826c8fdd8cdc64e |
|
BLAKE2b-256 | d72b182c22860eb6d70d0f2174a96da683b7b3ddfe8716c7818dbc8214cb53c2 |
Hashes for kornia_rs-0.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f6a82c6ed3e8237d018d371460bce367f6205718cb572e2c8dcbcdf6628eb3c |
|
MD5 | db054e05861eea2f6997b5eba08b0c96 |
|
BLAKE2b-256 | 547152cf05eb3b120f75d9d162ce83e438da1fa45180710249ac00f2766bdee6 |
Hashes for kornia_rs-0.1.1-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a00826779f068008e751757b0f4012223759967516492b80c7680185dd42638 |
|
MD5 | 5b075f406cc27f23a69530e53bfabb09 |
|
BLAKE2b-256 | 028025633146741522fdc393ceb384a6761aa2c5638ae39d46dc6e4af9b8e77b |
Hashes for kornia_rs-0.1.1-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3094eb2c7f27bbe0acb95b66585b62e5da62db0d02e950a055a602899a05c665 |
|
MD5 | b4fb1beaa6ae33ab8454f197a25c5233 |
|
BLAKE2b-256 | 0c1a830c3705ec28e60d3c9f5245700a63b73fd220416ebf7ac2e6ef483f0d36 |