A lightweight, robust, and standalone pipeline for image registration using the SIFT (Scale-Invariant Feature Transform) algorithm.
This project is built using Pure OpenCV and NumPy, meaning it does not require heavy deep learning frameworks like PyTorch or TensorFlow. It extracts keypoints, matches them using Nearest Neighbor distance ratio, estimates affine transformations (via RANSAC or LMEDS), and generates comprehensive visual evaluations (Heatmaps, Error lines, Displacement Vector Fields, and Checkerboards).
- Standalone & Lightweight: No PyTorch dependency. Pure NumPy mathematical operations.
- Auto-Thresholding: Automatically adjusts the Nearest Neighbor ratio threshold if too few matches are found.
- Multiple Execution Modes: Run via Command Line Interface (CLI) or Jupyter Notebook.
- Batch Processing: Support reading image pairs directly from the terminal or via a CSV file.
- Comprehensive Visualization: Generates side-by-side matches, error line plots, and checkerboard blends to visually verify the alignment accuracy.
We highly recommend using a Virtual Environment (venv) to keep your dependencies clean.
If you are on a Unix-based system, you can use the provided Makefile to automatically install system dependencies, create a virtual environment, and install the required Python packages.
- Open your terminal in the project directory.
- Run the setup command:
make setup
- Activate the virtual environment:
source .venv/bin/activate
If you prefer to install things manually or are using Windows:
- Create a virtual environment:
# macOS/Linux
python3 -m venv .venv
source .venv/bin/activate
# Windows
python -m venv .venv
.venv\Scripts\activate
- Install the required minimalist libraries:
pip install --upgrade pip
pip install opencv-python numpy matplotlib scikit-image tqdm jupyter ipywidgets
You can run the script SIFT_align_image.py using two main methods.
Use the --img_list argument followed by pairs of images (Source and Target).
python SIFT_align_image.py --img_list ./images/eye1_src.jpg ./images/eye1_tgt.jpg ./images/eye2_src.jpg ./images/eye2_tgt.jpg
Create a .csv or .txt file (e.g., my_pairs.csv) where each line contains the path to the source image and the target image, separated by a comma:
test_images/src_1.jpg, test_images/tgt_1.jpg
test_images/src_2.jpg, test_images/tgt_2.jpg
Then run:
python SIFT_align_image.py --img_file my_pairs.csv
You can customize the execution using the following arguments:
--nn_threshold(float): Initial Nearest Neighbor ratio threshold. Default is0.7.--method(string): Affine estimation method. Choices areRANSAC(default) orLMEDS.--save(int):0: Saves only the evaluation plot.1(Default): Saves the evaluation plot AND the original 256x256 color images (source,target,warped).
Full Command Example:
python SIFT_align_image.py --img_file my_pairs.csv --nn_threshold 0.75 --method LMEDS --save 1
If you prefer an interactive environment, use the SIFT_align_image.ipynb file.
- Start Jupyter Notebook from your terminal (ensure your
.venvis activated):
jupyter notebook
- Open
SIFT_align_image.ipynb. - Scroll down to Cell 4: Configuration / Parameters.
- Modify the variables directly in the cell to fit your needs:
# Option 1: Provide a direct list of image paths
img_list = ['test_images/src.jpg', 'test_images/tgt.jpg']
# Option 2: Provide a path to a CSV file (Leave img_list as [] to use this)
img_file = "my_pairs.csv"
nn_threshold = 0.7
method = 'RANSAC'
save_images = 1- Click "Run All" to execute the pipeline. The output logs and progress bar will appear within the notebook.
Upon successful execution, the script will automatically create a timestamped folder inside the output/ directory (e.g., output/SIFT_Standalone_20260224-153000/).
Inside this folder, you will find:
pair_000_imgName_result.png: A high-resolution matplotlib figure showing matches, error vectors, and checkerboard blends.pair_000_imgName_src.png,*_tgt.png,*_warp.png: The standalone 256x256 color images (if--save 1was used).results_log.csv: A summary log containing the file paths, number of valid SIFT matches found, and the execution status of each pair.
SIFT_align_image.py: The main command-line executable.SIFT_align_image.ipynb: The interactive Jupyter Notebook version.SIFT_align_image_functions.py: The core engine containing pure NumPy math, metrics (MSE, TRE, SSIM), and Matplotlib plotting logic.Makefile: Automation script for environment setup.