{"id":2558,"library":"kornia-rs","title":"Kornia-rs","description":"Kornia-rs is a low-level computer vision library primarily written in Rust, offering high-performance image I/O, processing, and 3D operations through Python bindings. It leverages Rust's memory safety and speed for demanding computer vision tasks, integrating efficiently into machine learning and data science workflows via zero-copy data transfer with frameworks like NumPy and PyTorch. The library is actively developed by the Kornia organization and is currently at version 0.1.10.","status":"active","version":"0.1.10","language":"en","source_language":"en","source_url":"https://github.com/kornia/kornia-rs","tags":["computer vision","image processing","rust","bindings","performance","deep learning","dlpack","image-io"],"install":[{"cmd":"pip install kornia-rs","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Used for zero-copy conversion of kornia-rs Tensors to NumPy arrays via DLPack.","package":"numpy","optional":true},{"reason":"Used for zero-copy conversion of kornia-rs Tensors to PyTorch Tensors via DLPack.","package":"torch","optional":true}],"imports":[{"note":"While direct imports are possible, aliasing 'kornia_rs' as 'K' is a common convention demonstrated in official examples, allowing for a consistent API access pattern.","wrong":"from kornia_rs import read_image_jpeg","symbol":"kornia_rs","correct":"import kornia_rs as K"}],"quickstart":{"code":"import kornia_rs as K\nimport numpy as np\nimport os\n\n# For demonstration, create a dummy image file if it doesn't exist\n# In a real scenario, replace 'dummy.jpeg' with your image path.\nif not os.path.exists('dummy.jpeg'):\n    try:\n        from PIL import Image\n        img = Image.new('RGB', (256, 256), color = 'red')\n        img.save('dummy.jpeg')\n        print(\"Created 'dummy.jpeg' for quickstart.\")\n    except ImportError:\n        print(\"Pillow not installed. Skipping dummy image creation.\")\n        print(\"Please create a 'dummy.jpeg' file or adjust the quickstart path.\")\n        exit() # Or handle gracefully without exiting\n\n# 1. Read an image into a kornia_rs.Tensor\n# This uses the image-rs backend by default (or turbojpeg if enabled/available).\nimage_tensor = K.read_image_jpeg('dummy.jpeg')\nprint(f\"Original image tensor shape: {image_tensor.shape}\")\n\n# 2. Convert the kornia_rs.Tensor to a NumPy array (zero-copy via DLPack)\nnp_image = np.from_dlpack(image_tensor)\nprint(f\"NumPy array shape: {np_image.shape}, dtype: {np_image.dtype}\")\n\n# 3. Perform a basic image operation, e.g., resize\n# The resize function expects a kornia_rs.Tensor and returns one.\nresized_tensor = K.resize(image_tensor, (128, 128), interpolation=\"bilinear\")\nprint(f\"Resized image tensor shape: {resized_tensor.shape}\")\n\n# Convert resized tensor back to NumPy for further processing or visualization\nnp_resized_image = np.from_dlpack(resized_tensor)\nprint(f\"Resized NumPy array shape: {np_resized_image.shape}, dtype: {np_resized_image.dtype}\")\n\n# Clean up dummy image if created\nif os.path.exists('dummy.jpeg') and 'Created' in locals():\n    os.remove('dummy.jpeg')\n    print(\"Removed 'dummy.jpeg'.\")","lang":"python","description":"This quickstart demonstrates how to read an image using `kornia-rs`, convert the resulting `kornia_rs.Tensor` to a NumPy array via DLPack for seamless integration with Python data science tools, perform a basic image processing operation like resizing, and then convert the result back to a NumPy array. This highlights the library's high-performance I/O and interoperability."},"warnings":[{"fix":"Always consult the latest GitHub README and release notes when upgrading, and adapt your code to new API signatures. Pin your minor version to ensure stability within a project (e.g., `kornia-rs==0.1.*`).","message":"As a library in active development and in early versions (0.1.x), expect potential breaking changes between minor versions. API signatures, especially for core functionalities like `warp_affine` or tensor allocators, have undergone refactoring in past releases.","severity":"breaking","affected_versions":"<=0.1.10"},{"fix":"Check the `kornia-rs` GitHub documentation for a full list of optional system dependencies relevant to the features you intend to use and install them manually if needed.","message":"Certain features, such as optimized JPEG decoding (via `turbojpeg`) or video processing (via `gstreamer`), may require additional system-level dependencies (e.g., `nasm`, `libgstreamer1.0-dev`). These are not automatically installed with `pip install kornia-rs`.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to the `kornia` (PyTorch) documentation or `kornia-rs` specific documentation for the exact Python-exposed functions and objects. Avoid assuming direct parity with the Rust API.","message":"Kornia-rs is a Rust-first library with Python bindings. Only a subset of the full Rust API is exposed to Python. Not all functionalities available in the Rust crate are directly accessible from Python.","severity":"gotcha","affected_versions":"All"},{"fix":"Be mindful of shared memory when performing operations on tensors converted via DLPack. If independent copies are needed, explicitly clone the tensor after conversion (e.g., `np_array = np.from_dlpack(image_tensor).copy()`).","message":"The `kornia_rs.Tensor` objects use DLPack for zero-copy data transfer to NumPy and PyTorch tensors. While highly efficient, this means direct modifications to the underlying `kornia_rs.Tensor` after conversion might affect the derived NumPy/PyTorch tensors, and vice versa.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}