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.
🛠️ 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_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.2-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a8f0135bb002edf72214dbd249ed7ccdcd9eb8c303332fdb2b190f37c2087ba |
|
MD5 | cccaf19442d2b666d08f2cd59ca1aee4 |
|
BLAKE2b-256 | 19c6a9e925787a061af43f49083f8335e186a5f3495bdea0f3971f833b21050a |
Hashes for kornia_rs-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2ddac3f7c71ef6750da3b90393c52cd873047a56af96e0cde8cf6de377aa3c0 |
|
MD5 | 43a2844c3cc4cbec5b391edd48748c86 |
|
BLAKE2b-256 | e1d8a3ee42bacf62c94ba2754174bdf5b0d07fc5a8dca6cf226e5bf10ed13a9c |
Hashes for kornia_rs-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 586aff2e2ce596936c64ab9b02d654e11166f0912282b95c02a15ab63a985cb7 |
|
MD5 | 2bf347ad41142c452ce252d3d5a4d796 |
|
BLAKE2b-256 | d5e5ffac64637823884962ea618ecb0079da4df2e81e15657d8316a59d3ead23 |
Hashes for kornia_rs-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb2f36b5b4048146fd5d73c5bd536a99dd7ab1a7b276c8b432038fd262d5908 |
|
MD5 | 11015e9d81ad1f16e16bf1e99807042f |
|
BLAKE2b-256 | 1becce3743fdece9cf3a239011a212b2f9ed6b053cabcd53fe143c4106a33fb8 |
Hashes for kornia_rs-0.1.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c96ba400223b3bc863f494ada1b65bfd30783f8665d54899c7c673abaee842be |
|
MD5 | 3f9bf1eed706370062345932cad94a13 |
|
BLAKE2b-256 | d27aac19acf00bb3bf9c60c86646646894612cf7166a3eddc7a9d93140b706e8 |
Hashes for kornia_rs-0.1.2-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4de0688535c3cb0ab4a93df5511a6dc7b7bd24eb3a5c842665e4e60d25997511 |
|
MD5 | 3493e9daded517cf7a0ad0d4d7911002 |
|
BLAKE2b-256 | 16e61c29f436e882fcd15d7e2ebd13d178197fbb4f6e2885147cf1d44d75bcf2 |
Hashes for kornia_rs-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5edafa835abcdfa6cf8b94684eaef8c5df8ea13949bfe9048ddd0a901b2d200 |
|
MD5 | f8451e7683b52c833b2f1576596f8471 |
|
BLAKE2b-256 | d007f531801e3a1b26ced41c579c93c509715051585823f6a0ec1148da03902e |
Hashes for kornia_rs-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c323ccb05518d965fd96b079aea05298ceb3631fdea4fcf3de8f16a6bb3aa34 |
|
MD5 | d2560ce09c78fc6345ae6452a9d8ba65 |
|
BLAKE2b-256 | 2e0390366c791e495670162497092e901272d70ee6fb712a75c42e21f8b42011 |
Hashes for kornia_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a0ebaa37642a37f228f435b3382656981fc2e5c8f7187f74361d5e2d595bf55 |
|
MD5 | b5dfcc1663f5454dee9940464a67aa59 |
|
BLAKE2b-256 | 11bc44f42e780cdda8420839af34ca0b2bf54dfe622b75b4053bfafe77ffafcf |
Hashes for kornia_rs-0.1.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bb6265532a3012a6818c4b4ec1e617cb47f259e1a9aae9a6c7a8987deaefc8e |
|
MD5 | 7f95c7e322379247cc11a2aaa2ed4c6f |
|
BLAKE2b-256 | 177050f398bfa5e83d81a4f6f14a9b5ccb8864fbfffbc38e524ee41d377c5893 |
Hashes for kornia_rs-0.1.2-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b0b4a0a44c2eb1050af1e64cd887ee654f1b4b101c3cad718413515d7b152a0 |
|
MD5 | 511ff47a90a679a41959d546b3e5c77b |
|
BLAKE2b-256 | 29cfcdce4a1d424532d244fa8908241154f4a23f4e36a135bc88e160f369f150 |
Hashes for kornia_rs-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb627590ccfabcfb0fdc39cf186d4abf5eee017c74a9bdf1903ca0bc6b4192f0 |
|
MD5 | 541c49edf30a5d45bb6759f057184600 |
|
BLAKE2b-256 | 7befeec16e87bc8893f608a42c96739ad0c35e30877b0f64bd19d95971534cef |
Hashes for kornia_rs-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15bfc18b27e976c5c23b7ff0c1de04342595db2f149e83b1f75b7d6066668667 |
|
MD5 | 7845a849a08d3aa19163b3dce468642d |
|
BLAKE2b-256 | d4a8d6ad7a6b90e33541fbd7e02c86ab8e382fff7cb56b1debefaa1589d305d5 |
Hashes for kornia_rs-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 256747d123613ec0c7d7876b89c89f1d19d07e40aae01fbef136552cd18ced78 |
|
MD5 | 9528aea0d23daa21aaf68c42e4c84c92 |
|
BLAKE2b-256 | 1897f852e026793a3fcbcfb5eda5b540447c6b68ad71ff4824a244922b2c7fd0 |
Hashes for kornia_rs-0.1.2-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83f1d2b4e2201a2d0cb635cd9e2cadb63272f61593c2b6b3efa1985d67001ae1 |
|
MD5 | 7c5a6b7ea7b7bb4471636d926f933198 |
|
BLAKE2b-256 | c6b4bc31a8f35d5ca53e364c17bf8816eb5684d4f96b7112d977ac16271ee2b5 |
Hashes for kornia_rs-0.1.2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e626f4e4e77adf26ad238da1ef978f87427a93c1c54f3a7b2c0ee2d81865cf2 |
|
MD5 | 7c1092c45401201c46281c6d76166986 |
|
BLAKE2b-256 | 06cf1e1016c4b946c839a3cd9100ec4c67e55bddc85f10d921bb5857cff0e360 |
Hashes for kornia_rs-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b1c45cfcc006b06b9a5a2284bc743a38cf297faea087d18e866b093f0800cdf |
|
MD5 | a0aa38aa178773af0693a8e325df4855 |
|
BLAKE2b-256 | 78e58e26aad206d276125a843bd63937f6a00e7fe720d400c21eeba241e69ca3 |
Hashes for kornia_rs-0.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f3777ca772efcf892ec17a4930c47b86dbc9079b46773b54dd03d7887eb29e2 |
|
MD5 | 1b94a6b2aa68108056fc0f8909bfee31 |
|
BLAKE2b-256 | 944a2387a112ca38a1f86fbe32a7c38d48a315a8c922229754c5e69f696c373c |
Hashes for kornia_rs-0.1.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16422daf545630778866f66a51361e50ce9e89a5e8197a25f2450ceada2d11a3 |
|
MD5 | 3cd036473bf4a25c8bf72b98e6766f3a |
|
BLAKE2b-256 | e1df0796bc3f28e2f9e43e132f2e4383e90c27a73d70f39c718dab0e1c006e92 |
Hashes for kornia_rs-0.1.2-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 481fbf61af2ae9a15d9de5d2bd6969afcc5f6db63a3f6e02b264c95106f3134e |
|
MD5 | 2c18681d412383e0e62055ea53077f1c |
|
BLAKE2b-256 | 021e9c12171ae6689dce406c179abd681173dae9fb9cc13e048c5f3948164423 |
Hashes for kornia_rs-0.1.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a706f99fea3f183612559071a29f032eeba2706871d23dee891c520f0d53c4d5 |
|
MD5 | 81e1c66f67b242a778911ed1093707ad |
|
BLAKE2b-256 | b455dac234b2e46ccf240659c782adc434a148ac497fb9ef4efb61f4801b39d4 |
Hashes for kornia_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e76dbdb7e40b611e7000b087a54202869e568389915bff18702f80f6f95d6123 |
|
MD5 | 8342de950aa0fe0626153b1de289bfba |
|
BLAKE2b-256 | 010aefbf59b0a6140153e05ff2576b2980637cf7b3d7a3587623e766c835c700 |
Hashes for kornia_rs-0.1.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dd7c8e71f1e80a3f034ef99f8892287d2ea9e248b0ad666795131fbd17eb6b7 |
|
MD5 | 571a6dca43d0d4a60c2d5dfbb1093156 |
|
BLAKE2b-256 | 504b54c98eb427f28ceb0a27927d9e90a2e23e5aa003a51681e3a8b334f890dd |
Hashes for kornia_rs-0.1.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d5a65aa3034d1dbb6d04f8f5613eb0e779187db729b70fe27cbb765fd4c0b91 |
|
MD5 | d90bd55bde1a29883402318736bc1667 |
|
BLAKE2b-256 | 7edc5672b4e93b955d1a83d79b596e402730a67e94300e2cdb20c74638b0cc96 |
Hashes for kornia_rs-0.1.2-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df5e65732e8aa1c3540c83a5661f97d648ba282cc5723e1b10d1fda25984f170 |
|
MD5 | 7f2542e3c1487d5cf210ba1492df734b |
|
BLAKE2b-256 | e628fe41a8e20010176f57f3606b194209f5fa542aadfb41e806557200887c08 |
Hashes for kornia_rs-0.1.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88fcddc24fb000739b7360d3adcda12c7745fb678c0da42bbcfedd5eb69dfc22 |
|
MD5 | 2a398cc682ec5c8fceb464c2182934ba |
|
BLAKE2b-256 | 226a0552062395fd7a042b24d40af96b838ed049bed614e49cc4583c1311992d |
Hashes for kornia_rs-0.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc20f575437c83060fe83997a9778a931f26a6e2b6de302dac21246436419e7 |
|
MD5 | 2ed7e36c8c9b51a5ac5497d24c919595 |
|
BLAKE2b-256 | 4a19cbb7c8fa0a05bdce2fc2f894f0edfba2719936c0ae53a1fd7ccd15974f01 |
Hashes for kornia_rs-0.1.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4e904c62b594aac8705c42385ad2a6a8bab1ceed5ee29d0f9edd2729883d7bf |
|
MD5 | 45b75e680fc79a8211069fbc5c5053f5 |
|
BLAKE2b-256 | c4b709e2cf59b9ef523a8c8635de5498458a0c0983c6c20af96ddb89fc19830a |
Hashes for kornia_rs-0.1.2-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d5a16960134bd0f0cfd973207d432a76ee8b938bf13eef200e42eaa47bcd09f |
|
MD5 | 0bc048c14c5927495dbb059ff04ceb17 |
|
BLAKE2b-256 | afe280e835f6adc0e29c163f3f477d612034f2f18dbd6c6c25c1c086e7be534a |
Hashes for kornia_rs-0.1.2-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac85497c891ff9293d56fa01cc64e48cafed0524edc3c34ad0c51856eb0b589c |
|
MD5 | 76ffebec02ff3bdeb1487266c807bf14 |
|
BLAKE2b-256 | 61d9423a525815b7a91337c3dab45e40f8bab0c4821b58d7ce7bb4ad4ec8cd73 |