Implementation:Kornia Kornia ImageStitcher
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Vision, Geometry, Image_Processing |
| Last Updated | 2026-02-09 15:00 GMT |
Overview
Concrete tool for automated panoramic image stitching provided by Kornia's contrib module.
Description
The ImageStitcher class implements end-to-end image stitching as an nn.Module. It chains:
- Preprocessing — grayscale conversion for the matcher.
- Feature matching via a pluggable matcher (LoFTR or LocalFeatureMatcher).
- Homography estimation via RANSAC or vanilla DLT.
- Perspective warping of the source image into the reference frame.
- Naive blending of warped and reference images.
It processes images sequentially from left to right, stitching pairs iteratively. The postprocess step crops redundant black borders from the result.
Usage
Initialize with a matcher module and estimator type. Pass images in left-to-right order. Use with torch.inference_mode() to save memory.
Code Reference
| Repository | https://github.com/kornia/kornia |
|---|---|
| File | kornia/contrib/image_stitching.py
|
| Lines | L30–155 |
| Signature | class ImageStitcher(nn.Module): def __init__(self, matcher: nn.Module, estimator: str = "ransac", blending_method: str = "naive") -> None
|
| Forward | def forward(self, *imgs: torch.Tensor) -> torch.Tensor
|
| Import | from kornia.contrib import ImageStitcher
|
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
matcher |
nn.Module |
Yes | Feature matcher such as LoFTR |
estimator |
str |
No | "ransac" or "vanilla"
|
blending_method |
str |
No | "naive"
|
*imgs |
torch.Tensor |
Yes | Variable number of images (1, 3, H, W) in left-to-right order
|
Outputs
Stitched panoramic torch.Tensor of shape (1, 3, H, W_panorama) with black borders cropped.
Usage Examples
import torch
from kornia.feature import LoFTR
from kornia.contrib import ImageStitcher
from kornia.io import load_image
from kornia.utils import tensor_to_image
# Initialize matcher and stitcher
matcher = LoFTR(pretrained="outdoor")
stitcher = ImageStitcher(matcher, estimator="ransac")
# Load images and add batch dimension
img1 = load_image("left.jpg", device="cuda")[None]
img2 = load_image("right.jpg", device="cuda")[None]
# Stitch with reduced memory usage
with torch.inference_mode():
panorama = stitcher(img1, img2)
# Visualize
import matplotlib.pyplot as plt
plt.imshow(tensor_to_image(panorama))
plt.show()
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment