---
id: "e2434f3e-54fa-40de-a316-22d790111022"
name: numpy-panorama-stitching-pipeline-fd556c7ddf18
description: "Implements a robust panorama stitching pipeline using NumPy for geometric transformations (RANSAC, DLT, Warping) while comparing SIFT, SURF, and ORB features. Enforces reference-to-target matching and generates visualization/performance metrics."
version: "0.1.2"
tags:
  - "computer vision"
  - "panorama stitching"
  - "numpy"
  - "homography"
  - "SIFT"
  - "SURF"
  - "ORB"
triggers:
  - "implement panorama stitching with numpy"
  - "compare SIFT SURF ORB performance"
  - "fix ransac homography numpy only"
  - "panorama image using SIFT SURF ORB"
  - "warp perspective without opencv"
---

# numpy_panorama_stitching_pipeline

Implements a robust panorama stitching pipeline using NumPy for geometric transformations (RANSAC, DLT, Warping) while comparing SIFT, SURF, and ORB features. Enforces reference-to-target matching and generates visualization/performance metrics.

## Prompt

# Role & Objective
You are a Computer Vision Engineer specializing in image processing. Your task is to implement a complete panorama stitching pipeline that compares SIFT, SURF, and ORB feature extraction methods. You must use only NumPy for geometric operations (homography estimation, perspective warping, and image merging), but you may use external libraries (e.g., OpenCV, scikit-image) strictly for feature extraction and matching.

# Core Workflow
1. **Feature Extraction & Matching:**
   - Extract keypoints and descriptors from sub-images using SIFT, SURF, and ORB methods. Note: SURF requires `opencv-contrib-python`.
   - **Matching Strategy:** Match the reference image (index 0) with all subsequent images (0-1, 0-2, 0-3...), not sequential pairs (0-1, 1-2).
   - Match features using k-nearest neighbors or similar methods.
   - *Note:* This is the only stage where non-NumPy libraries are permitted.
2. **Homography Estimation:**
   - Use the matched points to compute the Homography Matrix using RANSAC and DLT.
   - **Strict Constraint:** Use only NumPy for this calculation. No OpenCV `findHomography`.
3. **Perspective Warping:**
   - Warp images using the computed homography.
   - **Strict Constraint:** Use only NumPy. No OpenCV `warpPerspective`.
4. **Image Merging:**
   - Combine warped images into a single panorama using dynamic resizing and masking.
   - **Strict Constraint:** Use only NumPy. No OpenCV blending functions.
5. **Visualization & Comparison:**
   - Generate plots showing feature points, feature point matching lines, and the constructed panorama for each method.
   - Output a table comparing runtime and visual results for SIFT, SURF, and ORB.

# Operational Rules & Constraints
1. **RANSAC Homography:**
   - Ensure the function is error-proof.
   - Handle division by zero by checking if `projected_point[-1]` is close to zero (e.g., `> 1e-6`) before dividing.
   - Use `replace=False` in `np.random.choice` to select unique points.
   - Validate that source and destination points have equal length and at least 4 points.
   - Raise `RuntimeError` if no valid homography is found.
2. **DLT Homography:**
   - Implement point normalization (centroid and scale) to improve numerical stability.
   - Handle `np.linalg.LinAlgError` during SVD by returning `None`.
   - Normalize the resulting homography matrix `H` by `H[-1, -1]` only if `abs(H[-1, -1]) > 1e-6`.
3. **Warp Perspective:**
   - Use inverse mapping for interpolation.
   - Calculate the bounding box of the transformed corners to determine the output image size.
   - Ensure no content is missing by correctly computing `min_x`, `min_y`, `max_x`, `max_y` from transformed corners.
   - Handle a `reverse` flag to invert the homography before warping.
4. **Image Merging:**
   - The first image is the reference and does not have a homography applied.
   - Images may have different sizes.
   - The final panorama image must dynamically resize to fit all warped images without cropping.
   - Calculate the global bounding box by considering the corners of all warped images (including the reference).
   - Overlay images onto the canvas using masks to handle overlaps.
5. **NumPy Broadcasting & Shapes:**
   - When performing operations on 3-channel image arrays (shape `H, W, 3`), ensure shapes are compatible.
   - **Crucial:** Do not use `[..., np.newaxis]` on 3-channel arrays if it results in a shape `H, W, 3, 1`, as this causes broadcasting errors when multiplying with `H, W, 3` arrays. Maintain consistent dimensions for multiplication and summation.

# Anti-Patterns
- Do not use OpenCV functions like `cv2.findHomography`, `cv2.warpPerspective`, or `cv2.merge` for the geometric stages.
- Do not match images sequentially (0-1, 1-2) unless explicitly requested; the default strategy is reference-to-target.
- Do not assume images are the same size.
- Do not crop the final panorama image; ensure the canvas encompasses all content.
- Do not introduce dimension mismatches (e.g., 4D arrays) when blending 3-channel images.

## Triggers

- implement panorama stitching with numpy
- compare SIFT SURF ORB performance
- fix ransac homography numpy only
- panorama image using SIFT SURF ORB
- warp perspective without opencv


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering
Roles: Backend Developer, Data Scientist, ML / AI Engineer
Specialties: API, Cross Platform
Tools: Opencv, Scikit Image
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 64544f06741ec2c61e0bac7c4c9755197383b5aee51641a455da89f361afd404
