MaskRegistration is a tool for aligning segmentation masks between different DICOM series using SimpleITK.
Registration Steps:
- Convert the mask file to DICOM format in a temporary directory
- If auto-detect mode: try both slice directions (normal and reverse), compare results by number of preserved labels and pixels, pick the better one
- Optionally upsample target Z-axis by subpixel factor for finer registration
- Use ResampleImageFilter with nearest neighbor interpolation to align mask with target geometry
- If subpixel was used: downsample back using OR-logic (if any sub-voxel is positive, result is positive)
- Save result as NIFTI file
# Clone repository
git clone https://github.com/ludgerradke/MaskRegistration
cd MaskRegistration
# Install dependencies
uv syncThe web interface provides an interactive viewer for comparing source and target DICOM images with mask overlay.
uv run maskregistration-webOpens browser at http://localhost:8000.
| Area | Description |
|---|---|
| Left Sidebar | Load Source/Target DICOM, view spatial overlap, settings, export |
| Viewer | Curtain comparison with drag handle, slice navigation, zoom |
| Right Panel | Optional manual transform (Offset, Rotation, Scale) |
- Load source DICOM and mask
- Load target DICOM
- Registration runs automatically
- Use curtain to compare alignment
- Optionally adjust with manual transforms
- Export registered mask
uv run maskregistration -d1 <source_dicom> -m <mask> -d2 <target_dicom> -o <output>Required arguments:
- -d1, --input_dcm1 - Path to source DICOM folder
- -m, --input_mask - Path to mask file (NIFTI format)
- -d2, --input_dcm2 - Path to target DICOM folder
- -o, --output_mask - Path to output NIFTI file
Optional arguments:
- --reverse - Slice direction:
auto(default),true, orfalse - --subpixel N - Upsample factor for preserving small structures (default: 1)
Example:
uv run maskregistration -d1 dicom1 -m mask.nii.gz -d2 dicom2 -o output.nii.gz --subpixel 9# Install with dev dependencies
uv sync --extra dev
# Run tests
uv run pytest
# Format code
uv run black .