Usage
Image-Matchmaker can be used in three ways:
The Snakemake workflow — run the whole pipeline from a config file (recommended).
Individual scripts — run a single pipeline stage from the command line.
Python API — import and call functions directly.
1. Snakemake workflow (recommended)
This is the recommended way to run image-matchmaker and is covered in the
Quick Start. Activate the conda environment first
(e.g. conda activate imm_env); the workflows do not manage the environment
for you. --configfile is required — the workflows no longer ship with a default
config. The two workflows are:
# full registration
snakemake -s workflows/registration.smk --configfile <config.yaml> --cores 8
# apply the resulting transforms to other images
snakemake -s workflows/apply_transform.smk --configfile <config.yaml> --cores 8
See the Configuration Reference for the config fields and Understanding the Outputs for what each run produces.
2. Running individual scripts
Each pipeline stage is a standalone command-line script under image_matchmaker/. The
Snakemake workflow simply chains them together, but you can also run a single stage
yourself. Every script accepts --help for the full list of options.
The stages, in pipeline order:
raw_to_n5.py — convert inputs to .n5
python image_matchmaker/raw_to_n5.py --input_path <img> --output_path <out.n5> \
--output_key input --log_dir <dir> --x_res 1 --y_res 1 --z_res 1
Option |
Required |
Description |
|---|---|---|
|
yes |
Input image ( |
|
no |
Key of the input image in |
|
yes |
Output |
|
yes |
Key in the output |
|
yes |
Log directory |
|
no |
Voxel resolution (default |
prealignment.py — SVD pre-alignment
Option |
Required |
Description |
|---|---|---|
|
yes |
Fixed input |
|
yes |
Fixed input spacing (3 values) |
|
yes |
Moving input |
|
yes |
Moving input spacing (3 values) |
|
yes |
Output directory and key |
|
yes |
Path to write the final transform |
|
yes |
How to orient the principal axes ( |
|
no |
Also save a |
rigid_alignment_elastix.py — rigid Elastix alignment
Option |
Required |
Description |
|---|---|---|
|
yes |
Fixed prealigned input |
|
yes |
Moving prealigned input |
|
yes |
Output directory and key |
|
no |
Also save a |
cpd_nonrigid_registration.py — Coherent Point Drift
Option |
Required |
Description |
|---|---|---|
|
yes |
Fixed prealigned input |
|
yes |
Moving prealigned input |
|
yes |
Output directory |
|
yes |
CPD parameters (see Configuration Reference) |
match_pointclouds.py — feature matching
Option |
Required |
Description |
|---|---|---|
|
yes |
Fixed point cloud |
|
yes |
Registered moving point cloud |
|
yes |
Output directory |
|
no |
Matching algorithm: |
|
|
Minimum neighbours to consider for matching (required for |
|
no |
Maximum distance between neighbours to consider (default |
|
no |
Sinkhorn entropy regularization (default |
|
no |
Maximum Sinkhorn iterations (default |
The matching plot (point_matching, with the xy, xz and yz projections as three panels)
is written to a plots/ subfolder of the output directory.
elastix_deformable_pointset_registration.py — deformable B-spline
Option |
Required |
Description |
|---|---|---|
|
yes |
Fixed input |
|
yes |
Moving input |
|
yes |
Output directory and key |
|
yes |
Correspondence table between fixed and moving instances |
|
yes |
Output key for the result after applying the pre-alignment transform |
|
yes |
Pre-alignment transform path |
apply_transform.py — apply transforms to other images
Option |
Required |
Description |
|---|---|---|
|
yes |
Moving input path and key |
|
yes |
Resolution of the moving input |
|
yes |
Output path and key |
|
no |
Resolution of the moving output |
|
yes |
Interpolation order ( |
|
yes |
Log directory |
|
yes |
Elastix parameter map |
|
no |
Pre-alignment transform |
|
no |
Fixed input for overlay plots |
|
no |
Show verbose logs (flag) |
3. Python API
The package namespace is empty, so import from the submodules directly. Reusable
helpers are re-exported from image_matchmaker.utils:
from image_matchmaker.utils import (
read_volume, write_volume, get_attrs, # .n5 / zarr I/O
load_config, # parse a YAML config
plot_three_slices, plot_overlay, # visualization
rotate_img, resample_volume, # transforms
)
The point-cloud QC plots (plot_pcd_overlay, plot_displacement_field,
plot_matching_qc, plot_landmark_overlay) each draw the xy, xz and yz projections
as three panels in one figure. All but plot_landmark_overlay take a projections argument,
so projections=("xz",) gives a single view. All of them write through PLOT_FORMAT — see
the note below.
Higher-level stage functions are available from their modules, e.g.
prealign_samples / run_prealignment (image_matchmaker.prealignment),
run_cpd (image_matchmaker.cpd_nonrigid_registration), and run_matching
(image_matchmaker.match_pointclouds).
A minimal example — pre-align two masks and save an overlay:
import numpy as np
from image_matchmaker.prealignment import prealign_samples
from image_matchmaker.utils import read_volume, plot_overlay, prealignment_spacing
seg_fixed = read_volume("fixed_image.n5", key="seg")
seg_moving = read_volume("moving_image.n5", key="seg")
# the spacings must be numpy arrays, in (z, y, x) order and µm
fixed_spacing = np.asarray([0.4, 0.4, 0.4], dtype=np.float32)
moving_spacing = np.asarray([0.5, 0.4, 0.4], dtype=np.float32)
new_spacing = np.asarray(prealignment_spacing(fixed_spacing), dtype=np.float32)
results = prealign_samples(
seg_fixed, seg_moving, fixed_spacing, moving_spacing, new_spacing
)
fixed_prealigned = results["fixed"][0]
moving_prealigned = results["moving"][0]
plot_overlay(fixed_prealigned, moving_prealigned, save_path="overlay.pdf")
Note on the output format: every plotting helper saves through
image_matchmaker.utils.vis.PLOT_FORMAT, which is "pdf". The suffix you pass in
save_path is rewritten to it, so asking for overlay.png still writes overlay.pdf.
Set PLOT_FORMAT = None to keep the suffix you pass.
For complete, runnable examples of the Python API see examples/registration_test.py
(pre-alignment). Refer to each function’s source for its full signature.