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.3-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e0a2efd31bda9ba0c934b1359bb92834b1e9ccbf67f32445c9c56677f1109e0 |
|
MD5 | 1966f1b0552867e994a3f7176baf5103 |
|
BLAKE2b-256 | 6dce28809e78beb9ba19629b9bf6afb85722ccbd99928cf39325fb125aec9903 |
Hashes for kornia_rs-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6576c59e32a1721d53ca9712dbe62184f99e5967ca9532df4d5c0fcd762833c5 |
|
MD5 | 2ea09a488fa2d325faeb41ac03e083b2 |
|
BLAKE2b-256 | 656a3bb5a29922aba03e35223c14dc533cfea62f6afbaf4ccecb7c2d96f6e4ab |
Hashes for kornia_rs-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 027a2c7b43d75d41287ddcc365fd574024f2b3ab3a25427e9f3aa380d407702d |
|
MD5 | da5509856edc59e4da02399a4f4825a9 |
|
BLAKE2b-256 | 43e4074a4bb910d5116e3f29b8fc2d2df8226f6429a07193c4907bfd708152ff |
Hashes for kornia_rs-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e11649b25b402dc315998f654eb78ffbc55ba844436754b84b8781301f5219eb |
|
MD5 | 1e033f066377b81fe2ee9ecb04bc5125 |
|
BLAKE2b-256 | c8a34339d34978ec1483d1c5aab39182d37803fdfbaf5492617abb8e33eb6e34 |
Hashes for kornia_rs-0.1.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30a2ca3a23e8eb6b9fd503adb16a1cc3147cf2a1498e501ca9db6b779ec8430d |
|
MD5 | a958ec41b763b2be929be26f370eff9f |
|
BLAKE2b-256 | dec8148b3cef9bb28f9bcb17cd452dcaa7eabf768f1de9bce5f921ae6cd698e3 |
Hashes for kornia_rs-0.1.3-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24f547aa8c0f70951c36f80d396ec0dbf56a81ccb9ab7444b77d9c4b2d707939 |
|
MD5 | 5b870b9bfed2d3a6bebe877086a6e42e |
|
BLAKE2b-256 | 9eb379c63bde7b5503ab4e6e672df82a74f5fe704382371b6b1bc10afc99a693 |
Hashes for kornia_rs-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf20019bf3dc4af3742c41bbfbf7f2bc62fbf25b4e0e651663dee7332a73ec5f |
|
MD5 | 529a6731f78ec1893772cfeca8aeebbd |
|
BLAKE2b-256 | b51819dd6647859dd05d387812dcc376709a58f3612df2a3388992f1bca2ec8f |
Hashes for kornia_rs-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c464114e526089ab56b29004156b559226d429285d72857aa4b89d34dbe02b22 |
|
MD5 | c2e5524eb213943bd045e04b161ebc73 |
|
BLAKE2b-256 | a8bad4ae28610d52b6c9f3f0efcbf112cb3253c0665f03e794cd712ad48064fb |
Hashes for kornia_rs-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce2750720a9677a3900a7ba8a9ba5a8a4d6f60e30380ae0e41d3a2bf81c150b2 |
|
MD5 | e36fb7565a90544aaa02f0ee3b8604d0 |
|
BLAKE2b-256 | a928cf14b46049fff900c3cce76632d6738f353d9e4014c61e16cb389ea8f814 |
Hashes for kornia_rs-0.1.3-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b26d97b5b763893449cbfd154fa9edc6eeaf51980654c810ca9f5a0180fa762 |
|
MD5 | db016c0c3ef8efa559a6e490aac5c83e |
|
BLAKE2b-256 | 3b53a072f16c7ff81dbb7079d4dbbd39a80e1eedd7ed8e1ce4ba9e8ea4dda081 |
Hashes for kornia_rs-0.1.3-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3fdbec853c963722abdd421ff0ecc7ebc5eb1754cdf66cbe06ce32a0e6a804a |
|
MD5 | 8f11e9bbca6efdd27842d11b7d8f932a |
|
BLAKE2b-256 | e56d5f1f0e690f3363b770ec3690cf1d66bbed933efc4463e68ff97d44502c8b |
Hashes for kornia_rs-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce91aa5fa6d8068c33ba53bdf3cf943cb53ad8b14b06b2812dd10f104b61a161 |
|
MD5 | d6e7b71c0bd389149bfb7eae466558e8 |
|
BLAKE2b-256 | 480d665f7402f6b76ca345e257520567039a1b4e40fdca27ba4927407bbf273a |
Hashes for kornia_rs-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b8ef31b823c07b8ff30587c163ca280145ae867192a86ac4505bc73ae4be9a4 |
|
MD5 | a461f4dac8ff9da9f58cce6cac71376d |
|
BLAKE2b-256 | 13491460451d7b749c2d70e890279b69226aded33038ee74268fff62bf3957f9 |
Hashes for kornia_rs-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 530771c49b74fe70fa794ef2d5b9976c993e4dcb976b08608471949e4ef56e87 |
|
MD5 | 72c2618494801211fba183ded8bf0f26 |
|
BLAKE2b-256 | 38ff2a14bc06cf17e43774e5b54cacf787cc4f0e7357ec53dd98ba8664a70b22 |
Hashes for kornia_rs-0.1.3-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e57fa6c44dcaf896e2b3d9afad0e67b0c6615f5274c3c48d12fe37f4ae6f2a9b |
|
MD5 | f5a146c5da8108c9673ff4d96fd05267 |
|
BLAKE2b-256 | 7c6d39cd51eadc78cca67e1d52e2acb195d7c2529fa2b05e11b20033f06d2a6b |
Hashes for kornia_rs-0.1.3-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf7fa9fa33f3bcb12b7dc2f20d0d599eb6231ee237734c7ca91e8b9da6e4f273 |
|
MD5 | 4a320852168c4aefb819d82e55cd7333 |
|
BLAKE2b-256 | dfe6a555190a84bba722d1a1c3b363e8593eaec0b62eaf44946877f86b816b89 |
Hashes for kornia_rs-0.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f2f22e0b22c2ac8fc6366e6c1e7e30d726e7a836c21c551f20818066fe47a81 |
|
MD5 | 8fb38cf5223348949ee006b2f5d49fc5 |
|
BLAKE2b-256 | 83b25c4a3b49f27ea5555e6a992dbcb7f79a7d842a83e2b254a9273d89eac09d |
Hashes for kornia_rs-0.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ee5e8db42e15c8aee1b0c11e52f5eac2a4b5c33f375651829c9de4ec2e90976 |
|
MD5 | 5770e7ec8bdeebc73379e253400476ac |
|
BLAKE2b-256 | 59e123011c1b0d1dce535ba86f6b5fb898b7a3e80ff1ca7d318a8071baa54270 |
Hashes for kornia_rs-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8804834e0d4087cd36dcd123fbb45613bf99d760b1082c9d44c811a5aae35e51 |
|
MD5 | e36bf18d85b5ae9b67ad7d2282d5ddf9 |
|
BLAKE2b-256 | b773eee402d588f06860c7f6b02a6a8183915ed7e39176d0be12a3d585a05f7c |
Hashes for kornia_rs-0.1.3-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cfac9a37e433610e921b220aea6447ea3e7c6c9c7a8731641ad990419163340 |
|
MD5 | 8cda341ccc584a4cfe89aba2e8031248 |
|
BLAKE2b-256 | 422c0a86f28818d1b7c5d15bffe4ed62fbc1f5e28e66470fb58728baf99e920d |
Hashes for kornia_rs-0.1.3-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a50a171d4de3d13f9823ae38476b73b3f8fa1e27f06caf2515cc8dfae4ebb8 |
|
MD5 | ebcb6f1c58ad4db0b332a5ca4185f016 |
|
BLAKE2b-256 | cd1f7937b51fd1bdc174ed647230b40dfcc0aaae388eb682866ad55aa655fd95 |
Hashes for kornia_rs-0.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8465436de7120560f6cc0baadef601764778f7f0c649d362520acb591fe21354 |
|
MD5 | 04b8a92ca80f398637a35b1c95920c2a |
|
BLAKE2b-256 | 60e8eb689d7b2f2b4ea3acc1c2360c3e5977c0e2f08b8530051e621758e0704e |
Hashes for kornia_rs-0.1.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98a8c061c7fd5daa1a6002f07409fabd69946d34d908e614a26b7631c40e9c24 |
|
MD5 | 94d9bb0d16ba27131927a0dafa5a8a82 |
|
BLAKE2b-256 | 7293dcff574112709e6213f65c3a944737593c2e68ca2e997596392909846ce1 |
Hashes for kornia_rs-0.1.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1be4c499f481f628d018a96ef6267411b05a9946636acbe0272bce3d04ab0831 |
|
MD5 | 7181616758670688fb4b91c80e9f56e4 |
|
BLAKE2b-256 | 65a5f2f3240e11f3ebabdb8e097b5c9f6bfd96fcfd2ea4f433e72396d6c72379 |
Hashes for kornia_rs-0.1.3-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f97d6bc019ce84a5ef310c92f8bf4d30dcf06e43a75434cd05d46e16862b03cf |
|
MD5 | 8db2b1cc70d3f90491f51400587de712 |
|
BLAKE2b-256 | bdcf89ba6563eedbef5f9aff4c8dfa9747310797957e276ca005103be8cf76fe |
Hashes for kornia_rs-0.1.3-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f032064b731cee7270701641b3760af96344896e981ff24384431e649ab5781 |
|
MD5 | 1db08d3b0f147cc1c6386bce75da56b6 |
|
BLAKE2b-256 | 64329388eed9d848631ae0a7390ab2ee7755e3779ff4815f2200384c7b4b65ad |
Hashes for kornia_rs-0.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd9985169610d262771ebe6665314b25d520ed999f39bb4078723c75f5b0b66c |
|
MD5 | 6061797dbf898189a6ef66d43b66997c |
|
BLAKE2b-256 | b7e331e33ba40d68a8e9304bf403a21700170ba9e529e41631f3f9220787176f |
Hashes for kornia_rs-0.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebe498932ff56964f8a0b1ffc19061efe830a768bd88b6e7b33e71e739259b1d |
|
MD5 | 423cefef0dc19d5cfd6fe32198d9ee69 |
|
BLAKE2b-256 | 65c08aaee6c0e31f68b70f546a3916de13296ea61385b7b90737093e47c21c4d |
Hashes for kornia_rs-0.1.3-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 543ce2d78c1f994bf9c4a573d031a17544a52a3861dc11290282b08cd3dec132 |
|
MD5 | 90dbdb9abe3e400011dd493ffe0565a6 |
|
BLAKE2b-256 | 630bdbfd081f90cb93091d7f52e4b762222b5b7ab3d5312261dcdae271b7abf7 |
Hashes for kornia_rs-0.1.3-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa4e473907788807a8f9cc12e023f2c98a56cfda91fa5e4e12c309173be56fcf |
|
MD5 | 311cbe1c02d8293afae7fffb5c4d20b5 |
|
BLAKE2b-256 | 564d73b526613d1d275186e45dfc4323cd9602a51dd1743c2a92ebca9a3b4bd9 |