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. - 🐍 Python 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.5-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38b3acda17a9be3be3e888ecf32cab8362fa922d03bca6afd27ad0a8dac36fd2 |
|
MD5 | 735a70de5d0800e3f53b9649658e2ee2 |
|
BLAKE2b-256 | c443813d1145df813c4428068e3f7569ba7be0f82c5c201997e215a764c1df34 |
Hashes for kornia_rs-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be35764b4bf77eb973ad41e8ae5a7da8f99087eb2cc9119cc1cbd87c333fce88 |
|
MD5 | a23e57cc3747dd89212e29c0fe6bb606 |
|
BLAKE2b-256 | 4234e4248c4cacbacf944fa2112cb896c660eb889094c091ffbad2f4c7c73766 |
Hashes for kornia_rs-0.1.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3206d6e19b2fcf68b9e52a9a05354fd8eeb1ca6572ce69d568d120876f66556 |
|
MD5 | b49346b3b00ab411348fa40e53f529be |
|
BLAKE2b-256 | 2c2c15fb707cbcf95689cb2f7e5ea176f5d4c27f1b9c5b3b4d963a32181c3757 |
Hashes for kornia_rs-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0620ac05f0e6abc573bcaa6ab616e4448ba7131ecc06863591650326050603e |
|
MD5 | 98c86ccf5c67916ecbf8d3487c28888b |
|
BLAKE2b-256 | cea637b85efe460fb596e4d07dea4ed469c7e565ad15116222d586f24c29c804 |
Hashes for kornia_rs-0.1.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eec9792555247ca1906ff470e5a3368c1d401cceef1d4257a167165d3bf1f384 |
|
MD5 | d671f90ce12896ed1d6fbbc2b0e44761 |
|
BLAKE2b-256 | b6475ef9745d5d3ffbd2dcaf73df9fd448c55828225f8ab5531e241a799710e7 |
Hashes for kornia_rs-0.1.5-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9491d260bbdd43fad55e9bf15ade851be8b0fed4a341b9db40b1a8a43fab483b |
|
MD5 | 971eb00abdfc84ba12871c295749bffb |
|
BLAKE2b-256 | 03c3b2cfcbaf7621c20fc8e190fcb4eaa7179f74a7cc7fac97276990e01a2327 |
Hashes for kornia_rs-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1ab07db6ec5bcb5f0cd671bd7b5db1f3169dfc8a8b59b721a075a7edaa67e84 |
|
MD5 | 4dc9d7cdb16a4b6161e0d8cdae30851f |
|
BLAKE2b-256 | 643cc8e1eefc098dda7fd096676c653502406af6030e022de69ad4081b3fd662 |
Hashes for kornia_rs-0.1.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a1a73cb0d5a5d98f1174824ab69fb475e8191ead64ff8e2beb46b7ec5e201b |
|
MD5 | 80a91d375b9e598b4e929b8c30100ec8 |
|
BLAKE2b-256 | 8fc56e395cd1cc2f042011ee0d0c16c08311e7b05741e717083834a0683ac20b |
Hashes for kornia_rs-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c054e5b7550d4bb4d3e416182eab4fde32b3e58d39a832d08165bf2e4ba7e2a |
|
MD5 | 4cb94739eac0cab735367709d0decb73 |
|
BLAKE2b-256 | 95ec37f5e09230aa3bf68c3e1f25a9139b0d7265a9d345034eebcbfe59192e2c |
Hashes for kornia_rs-0.1.5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f8958ffb82dfd469fc403e9046c614230ea4fef7c9e551f0fa19865b81bedeb |
|
MD5 | 93eef9368336a3243a1f2f297fefa150 |
|
BLAKE2b-256 | b693947ce66cec0b307d7f948178ccdfcd52475a399e16e5e37705bf15fb6947 |
Hashes for kornia_rs-0.1.5-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90b966a74ebb37f820d11f9a89353b08acc3ef5dcab53616714b1cd483a2591d |
|
MD5 | dc1ed9533a00fc86487758e204f8e0ad |
|
BLAKE2b-256 | 46cbbbbceb04a94c1b12033ddb27a23e25627c5768fa52800d377eeb30d0db9f |
Hashes for kornia_rs-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c98aa837a43ada7ce61eefc19200008be8bc1a853c745e8448c1a54a77c7c45 |
|
MD5 | 697fb687ca50d75d1c274a6968890709 |
|
BLAKE2b-256 | 978e018fb96bd32ea7a164be07b452d5ab05d2bbcc90578a7db9b8e6f680439b |
Hashes for kornia_rs-0.1.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f33d2ce5022e41cbc91038875ffb6c1c4a3eaabd3702ef2fc7451fae0ed5a620 |
|
MD5 | 41e74576f3bec4a8d573ef3c4056ca18 |
|
BLAKE2b-256 | 758d2bc4e47334a366e742bcd1e1405d44c59a9b77408f39eecc0082b793a778 |
Hashes for kornia_rs-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92e26787918a7fb4732c4406ab1b0cad84720e9ffff2845c0a3cf9ad950e231d |
|
MD5 | 8acd6fb79faf3346734b8663d5c31150 |
|
BLAKE2b-256 | f252704128984d362ff3be440851757c59d07788f3b8b5b58eab4b121192d0da |
Hashes for kornia_rs-0.1.5-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 002a96b2a226a0ac20527c37690e72a9d01e4d70b8c340498515b9461959d005 |
|
MD5 | 953165a3137eb2192ec4b8c06f4d7126 |
|
BLAKE2b-256 | 852fa296f2b2c3d311054bf2c1da31ace4c43132c720a745a820dd116e05f401 |
Hashes for kornia_rs-0.1.5-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27ad0d7be0ee09995f10cfc0c297ad53a5bd187c368161fbe832aa1e8ce896aa |
|
MD5 | 50eeff792d43e4df91a3b5384b263435 |
|
BLAKE2b-256 | 358ddfe01b29b7d69a5113a609f79408eff7dd5d5fcd5a2161e244b0d8e349f4 |
Hashes for kornia_rs-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 324f359a06e05cad3feaceeacd70286b1c70fc69a39b3171bc81459f28e45cd1 |
|
MD5 | fbfe4537d7505308d014999c2d4c4a05 |
|
BLAKE2b-256 | 8ea8d3e3d3bc1a5d6232baf843fef375128c9c51c57dbed480b9451121740e83 |
Hashes for kornia_rs-0.1.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb862712aa7c19114a22e812cf580765c65be33f9dadcde4f332a0f56be6d82b |
|
MD5 | fbbc088fa81a1dfa5a31dc288c97144d |
|
BLAKE2b-256 | 240bf56d652d3bbf131f44e5efdf33c2f233d6211b373777a5599cce91ac40b4 |
Hashes for kornia_rs-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac1744c1650f0aff0c12489cdcbe5b8eef7d3ef5ae9236cc2cceaccc128a2b7 |
|
MD5 | 8925276cf220c70aeffab52c5da33036 |
|
BLAKE2b-256 | a6c0099b186c34fedb13f207dc263f08b3a15c65d30b02cea9aefa97c21a9aac |
Hashes for kornia_rs-0.1.5-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e37aab98e972c0c2497174de4422e4229f1ecae61c3a3b8ff79255277998bc66 |
|
MD5 | 885a013eacf515b5047051da8715603c |
|
BLAKE2b-256 | b08f095e9d449f35f142fe63cbc834e92d4e7ecd69dc5c6b6cde6d384df8b5ce |
Hashes for kornia_rs-0.1.5-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b010b91700a8e65e8319cbce88929a96053dd777cbb55500218260a73a5abd4b |
|
MD5 | 86cee80d4358bb8361cf9bccf1a44602 |
|
BLAKE2b-256 | 592d105f4f985e7fdaad57521f6273ce0a7a9554003fb15956be68214eecd49d |
Hashes for kornia_rs-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f6032293ebb367c8f66014f552bb2ee12e23fd22574674ead6033be8c55eaef |
|
MD5 | ae80aabf014d17378abb1c1493e41fdd |
|
BLAKE2b-256 | 9bdeab9b24ff5fe611da2d78a6c66717c684cc62bac4b0ecfe639218107a1e87 |
Hashes for kornia_rs-0.1.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8528dcc1c82fa661214a496f9a1482883dcb6529e07b72bd4fa81ae8c59699e |
|
MD5 | c4425cf7191cf15c76ec720b6a5cbae9 |
|
BLAKE2b-256 | 13f7d3172c6da8811cf1f690540a142292042a6e8354d9b25d57386404390e4a |
Hashes for kornia_rs-0.1.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fd1005c09b90421b3ef8333cef52030d0d200dde4b025697741e2ed2f5579e2 |
|
MD5 | e7bb880831b007500ed712dcee89de77 |
|
BLAKE2b-256 | f817b3d0b65340e8f1200c288d4f7ba9166ded0eb46c3f7f44fbc73e52a87397 |
Hashes for kornia_rs-0.1.5-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b8978f14b0740a17b5e42c6e5c0d519da219108dac90ee4cd45e55a9b353d04 |
|
MD5 | a8fa1c2abd8858506dc12ee293ae1522 |
|
BLAKE2b-256 | ec06975749fc073f10bdf782c1eff6e833a1cec2efbac02236deeae40406b885 |
Hashes for kornia_rs-0.1.5-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75f6952906f03cc4433f4d72680388742b6732a7773cd07a3473449dc5a4f1a5 |
|
MD5 | 677f2b85dd6d4728b9a22348f5ddef38 |
|
BLAKE2b-256 | b9698b277bb27f19568be6483208619c128495eaf8151b19fcd4289515becd5e |
Hashes for kornia_rs-0.1.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4ecb87f9213250e4bd948f19afb217e87612bb3b602769740b2c10c62d63d27 |
|
MD5 | f2d7087490b4f824c9a7167dca9da9a6 |
|
BLAKE2b-256 | 9c6e63ed943e53b96c76d1a50b6b390e69a8e61ecc0d25928103505dc1ebd522 |
Hashes for kornia_rs-0.1.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c58dd9cb330e5e472467e7238ab5aebee2df47553503fbbb434adaf1c67c83e |
|
MD5 | 57f930e6bb3e92c693aeeaf977c262dc |
|
BLAKE2b-256 | 4dd6d42809b62db6e94cdca7365f62585af25eca4568a0c690f49ffbd0cf4f4b |
Hashes for kornia_rs-0.1.5-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d75cfef465ac354a7464b1a711e8cbcb7341203a73634cf3197625907d9e4117 |
|
MD5 | de238545684970273cd9792fdb23d743 |
|
BLAKE2b-256 | a2fef926cee9622fceab8ec27ee461a56b12339d3b78e43723d7e95de4bf2e7a |
Hashes for kornia_rs-0.1.5-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dfd2327d6a6bd0ae57eb843fae3946f6220aac1285a89da1374e1b45384807e |
|
MD5 | 9d80d4522ce2d43e29e6bbe3b200d118 |
|
BLAKE2b-256 | 79556210c772f7d1b37032ba1f6a4888d87bd58bc0c015fa21bfcc5d80b6cdef |