A-tavv/multimodal-image-registration
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Multimodal CT/MRI Registration (SimpleITK)
This project implements a practical CT/MRI registration pipeline using SimpleITK/ITK:
- Preprocessing: resampling to common spacing, intensity normalization, histogram matching, and N4 bias correction.
- Registration: rigid then affine using Mattes Mutual Information with multi-resolution.
- Evaluation: Dice coefficient (if masks provided), overlay visualization, and deformation field inspection.
Setup
python -m venv .venv
source .venv/Scripts/activate
pip install -r requirements.txtQuick Start
python mir.py \Or create/edit config.json and simply run python mir.py; any CLI flags override the config values.
Bundled demo data lives under assets/sample_ct.nii.gz and assets/sample_mri.nii.gz; update config.json to point at those files for a ready-made example.
Features:
- Upload CT/MRI (NIfTI, MHA, PNG/JPG) and optional masks.
- Adjust target spacing + histogram matching.
- View overlay and deformation images instantly, download a ZIP of all outputs.
- Click “Load demo data” to preload the bundled synthetic volumes.
Using DICOM Directories
You can pass a directory instead of a single file for --fixed and/or --moving. The pipeline will automatically read the largest DICOM series. To target a specific series UID:
python mir.py \
--fixed "DICOM_CT_DIR" --fixed-series-uid "1.2.840...." \
--moving "DICOM_MR_DIR" --moving-series-uid "1.2.840...." \
--outdir outputsIf you omit --fixed-series-uid or --moving-series-uid, the series with the most slices is chosen.
Arguments --fixed-mask and --moving-mask are optional but recommended for Dice evaluation.
Outputs in outputs/:
preprocessed/fixed and moving images after normalization/matching.transforms/initial + final transforms (.tfm).registered/resampled moving aligned to fixed.eval/metrics JSON, overlays PNG, and deformation field visualization.
Notes
- NIfTI (
.nii/.nii.gz) or MHD/MHA recommended. DICOM series can be supported with minor changes. - If histogram matching oversmooths CT air/bone, disable via
--no-hist-match. - DICOM reading uses SimpleITK's GDCM; ensure
SimpleITKwheel includes GDCM (standard Windows wheels do). - Pass
--showto visualize the overlay interactively when the run finishes. - Defaults in
config.jsonlet you runpython mir.pywith zero arguments; tweak paths or parameters there for quick demos.
