{"id":20098447,"url":"https://github.com/kornia/kornia-rs","last_synced_at":"2025-05-14T14:02:14.608Z","repository":{"id":41480011,"uuid":"466513703","full_name":"kornia/kornia-rs","owner":"kornia","description":"🦀 Low-level 3D Computer Vision library in Rust","archived":false,"fork":false,"pushed_at":"2025-05-02T05:49:37.000Z","size":1206,"stargazers_count":325,"open_issues_count":82,"forks_count":65,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-02T06:29:41.082Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.rs/kornia","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kornia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-05T16:55:17.000Z","updated_at":"2025-04-30T07:14:16.000Z","dependencies_parsed_at":"2024-02-14T13:27:58.794Z","dependency_job_id":"c48b30ab-042c-4c03-8158-ecf9a7a71bcd","html_url":"https://github.com/kornia/kornia-rs","commit_stats":{"total_commits":229,"total_committers":9,"mean_commits":"25.444444444444443","dds":0.0786026200873362,"last_synced_commit":"e8bbc0e19c8e28702c8be63c5b6d33d09f1f632c"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornia%2Fkornia-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornia%2Fkornia-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornia%2Fkornia-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornia%2Fkornia-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kornia","download_url":"https://codeload.github.com/kornia/kornia-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159140,"owners_count":22024558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T17:03:50.104Z","updated_at":"2025-05-14T14:02:14.594Z","avatar_url":"https://github.com/kornia.png","language":"Rust","funding_links":["https://opencollective.com/kornia"],"categories":["Libraries","Computer Vision"],"sub_categories":["Image processing"],"readme":"# kornia-rs: low level computer vision library in Rust\n\n![Crates.io Version](https://img.shields.io/crates/v/kornia)\n[![PyPI version](https://badge.fury.io/py/kornia-rs.svg)](https://badge.fury.io/py/kornia-rs)\n[![Documentation](https://img.shields.io/badge/docs.rs-kornia-orange)](https://docs.rs/kornia)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENCE)\n[![Discord](https://img.shields.io/badge/Discord-5865F2?logo=discord\u0026logoColor=white)](https://discord.gg/HfnywwpBnD)\n\nThe `kornia` crate is a low level library for Computer Vision written in [Rust](https://www.rust-lang.org/) 🦀\n\nUse 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.\n\n## Getting Started\n\n`cargo run --bin hello_world -- --image-path path/to/image.jpg`\n\n```rust\nuse kornia::image::Image;\nuse kornia::io::functional as F;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // read the image\n    let image: Image\u003cu8, 3\u003e = F::read_image_any_rgb8(\"tests/data/dog.jpeg\")?;\n\n    println!(\"Hello, world! 🦀\");\n    println!(\"Loaded Image size: {:?}\", image.size());\n    println!(\"\\nGoodbyte!\");\n\n    Ok(())\n}\n```\n\n```bash\nHello, world! 🦀\nLoaded Image size: ImageSize { width: 258, height: 195 }\n\nGoodbyte!\n```\n\n## Features\n\n- 🦀The library is primarly written in [Rust](https://www.rust-lang.org/).\n- 🚀 Multi-threaded and efficient image I/O, image processing and advanced computer vision operators.\n- 🔢 Efficient Tensor and Image API for deep learning and scientific computing.\n- 🐍 Python bindings are created with [PyO3/Maturin](https://github.com/PyO3/maturin).\n- 📦 We package with support for Linux [amd64/arm64], Macos and WIndows.\n- Supported Python versions are 3.7/3.8/3.9/3.10/3.11/3.12/3.13, including the free-threaded build.\n\n### Supported image formats\n\n- Read images from AVIF, BMP, DDS, Farbeld, GIF, HDR, ICO, JPEG (libjpeg-turbo), OpenEXR, PNG, PNM, TGA, TIFF, WebP.\n\n### Image processing\n\n- Convert images to grayscale, resize, crop, rotate, flip, pad, normalize, denormalize, and other image processing operations.\n\n### Video processing\n\n- Capture video frames from a camera and video writers.\n\n## 🛠️ Installation\n\n### \u003e_ System dependencies\n\nDependeing on the features you want to use, you might need to install the following dependencies in your system:\n\n#### turbojpeg\n\n```bash\nsudo apt-get install nasm\n```\n\n#### gstreamer\n\n```bash\nsudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev\n```\n\n** Check the gstreamr installation guide: \u003chttps://docs.rs/gstreamer/latest/gstreamer/#installation\u003e\n\n### 🦀 Rust\n\nAdd the following to your `Cargo.toml`:\n\n```toml\n[dependencies]\nkornia = \"v0.1.9\"\n```\n\nAlternatively, you can use each sub-crate separately:\n\n```toml\n[dependencies]\nkornia-tensor = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\nkornia-tensor-ops = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\nkornia-io = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\nkornia-image = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\nkornia-imgproc = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\nkornia-icp = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\nkornia-linalg = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\nkornia-3d = { git = \"https://github.com/kornia/kornia-rs\", tag = \"v0.1.9\" }\n```\n\n### 🐍 Python\n\n```bash\npip install kornia-rs\n```\n\nA subset of the full rust API is exposed. See the [kornia documentation](https://kornia.readthedocs.io/en/stable/) for more detail about the API for python functions and objects exposed by the `kornia-rs` Python module.\n\nThe `kornia-rs` library is thread-safe for use under the free-threaded Python build.\n\n## Examples: Image processing\n\nThe following example shows how to read an image, convert it to grayscale and resize it. The image is then logged to a [`rerun`](https://github.com/rerun-io/rerun) recording stream.\n\nCheckout all the examples in the [`examples`](https://github.com/kornia/kornia-rs/tree/main/examples) directory to see more use cases.\n\n```rust\nuse kornia::{image::{Image, ImageSize}, imgproc};\nuse kornia::io::functional as F;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // read the image\n    let image: Image\u003cu8, 3\u003e = F::read_image_any_rgb8(\"tests/data/dog.jpeg\")?;\n    let image_viz = image.clone();\n\n    let image_f32: Image\u003cf32, 3\u003e = image.cast_and_scale::\u003cf32\u003e(1.0 / 255.0)?;\n\n    // convert the image to grayscale\n    let mut gray = Image::\u003cf32, 1\u003e::from_size_val(image_f32.size(), 0.0)?;\n    imgproc::color::gray_from_rgb(\u0026image_f32, \u0026mut gray)?;\n\n    // resize the image\n    let new_size = ImageSize {\n        width: 128,\n        height: 128,\n    };\n\n    let mut gray_resized = Image::\u003cf32, 1\u003e::from_size_val(new_size, 0.0)?;\n    imgproc::resize::resize_native(\n        \u0026gray, \u0026mut gray_resized,\n        imgproc::interpolation::InterpolationMode::Bilinear,\n    )?;\n\n    println!(\"gray_resize: {:?}\", gray_resized.size());\n\n    // create a Rerun recording stream\n    let rec = rerun::RecordingStreamBuilder::new(\"Kornia App\").spawn()?;\n\n    rec.log(\n        \"image\",\n        \u0026rerun::Image::from_elements(\n            image_viz.as_slice(),\n            image_viz.size().into(),\n            rerun::ColorModel::RGB,\n        ),\n    )?;\n\n    rec.log(\n        \"gray\",\n        \u0026rerun::Image::from_elements(gray.as_slice(), gray.size().into(), rerun::ColorModel::L),\n    )?;\n\n    rec.log(\n        \"gray_resize\",\n        \u0026rerun::Image::from_elements(\n            gray_resized.as_slice(),\n            gray_resized.size().into(),\n            rerun::ColorModel::L,\n        ),\n    )?;\n\n    Ok(())\n}\n```\n\n![Screenshot from 2024-03-09 14-31-41](https://github.com/kornia/kornia-rs/assets/5157099/afdc11e6-eb36-4fcc-a6a1-e2240318958d)\n\n## Python usage\n\nLoad an image, that is converted directly to a numpy array to ease the integration with other libraries.\n\n```python\n    import kornia_rs as K\n    import numpy as np\n\n    # load an image with using libjpeg-turbo\n    img: np.ndarray = K.read_image_jpeg(\"dog.jpeg\")\n\n    # alternatively, load other formats\n    # img: np.ndarray = K.read_image_any(\"dog.png\")\n\n    assert img.shape == (195, 258, 3)\n\n    # convert to dlpack to import to torch\n    img_t = torch.from_dlpack(img)\n    assert img_t.shape == (195, 258, 3)\n```\n\nWrite an image to disk\n\n```python\n    import kornia_rs as K\n    import numpy as np\n\n    # load an image with using libjpeg-turbo\n    img: np.ndarray = K.read_image_jpeg(\"dog.jpeg\")\n\n    # write the image to disk\n    K.write_image_jpeg(\"dog_copy.jpeg\", img)\n```\n\nEncode or decode image streams using the `turbojpeg` backend\n\n```python\nimport kornia_rs as K\n\n# load image with kornia-rs\nimg = K.read_image_jpeg(\"dog.jpeg\")\n\n# encode the image with jpeg\nimage_encoder = K.ImageEncoder()\nimage_encoder.set_quality(95)  # set the encoding quality\n\n# get the encoded stream\nimg_encoded: list[int] = image_encoder.encode(img)\n\n# decode back the image\nimage_decoder = K.ImageDecoder()\n\ndecoded_img: np.ndarray = image_decoder.decode(bytes(image_encoded))\n```\n\nResize an image using the `kornia-rs` backend with SIMD acceleration\n\n```python\nimport kornia_rs as K\n\n# load image with kornia-rs\nimg = K.read_image_jpeg(\"dog.jpeg\")\n\n# resize the image\nresized_img = K.resize(img, (128, 128), interpolation=\"bilinear\")\n\nassert resized_img.shape == (128, 128, 3)\n```\n\n## 🧑‍💻 Development\n\nPre-requisites: install `rust` and `python3` in your system.\n\nInstall rustup in your system\n```bash\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n```\n\nInstall [`uv`](https://docs.astral.sh/uv/) to manage python dependencies\n```bash\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n```\n\nInstall the [`just`](https://github.com/casey/just) command runner. This tool is used to manage the development tasks.\n```bash\ncargo install just\n```\n\nClone the repository in your local directory\n```bash\ngit clone https://github.com/kornia/kornia-rs.git\n```\n\nYou can check the available commands by running `just` in the root directory of the project.\n\n```bash\n$ just\nAvailable recipes:\n    check-environment                 # Check if the required binaries for the project are installed\n    clean                             # Clean up caches and build artifacts\n    clippy                            # Run clippy with all features\n    clippy-default                    # Run clippy with default features\n    fmt                               # Run autoformatting and linting\n    py-build py_version='3.9'         # Create virtual environment, and build kornia-py\n    py-build-release py_version='3.9' # Create virtual environment, and build kornia-py for release\n    py-install py_version='3.9'       # Create virtual environment, and install dev requirements\n    py-test                           # Test the kornia-py code with pytest\n    test name=''                      # Test the code or a specific test\n```\n### 🐳 Devcontainer\n\nThis project includes a development container to provide a consistent development environment.\n\nThe devcontainer is configured to include all necessary dependencies and tools required for building and testing the `kornia-rs` project. It ensures that the development environment is consistent across different machines and setups.\n\n**How to use**\n\n1. **Install Remote - Containers extension**: In Visual Studio Code, install the `Remote - Containers` extension from the Extensions view (`Ctrl+Shift+X`).\n\n2. **Open the project in the container**:\n    - Open the `kornia-rs` project folder in Visual Studio Code.\n    - Press `F1` and select `Remote-Containers: Reopen in Container`.\n\nVisual Studio Code will build the container and open the project inside it. You can now develop, build, and test the project within the containerized environment.\n\n### 🦀 Rust\n\nCompile the project and run the tests\n\n```bash\njust test\n```\n\nFor specific tests, you can run the following command:\n\n```bash\njust test image\n```\n\n### 🐍 Python\n\nTo build the Python wheels, we use the `maturin` package. Use the following command to build the wheels:\n\n```bash\njust py-build\n```\n\nTo run the tests, use the following command:\n\n```bash\njust py-test\n```\n\n## 💜 Contributing\n\nThis is a child project of [Kornia](https://github.com/kornia/kornia). Join the community to get in touch with us, or just sponsor the project: \u003chttps://opencollective.com/kornia\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkornia%2Fkornia-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkornia%2Fkornia-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkornia%2Fkornia-rs/lists"}