SimpleITK  
Elastix/Registration/elx.py
1#!/usr/bin/env python
2
3# This example demonstrates the usage of the SimpleElastix framework
4# for image registration using the ElastixImageFilter.
5
6import SimpleITK as sitk
7import sys
8
9if len(sys.argv) < 6:
10 print(
11 f"Usage: {sys.argv[0]} <fixedImage> <movingImage> <parameterFile> <outputImage> <outputParameterFile>"
12 )
13 sys.exit(1)
14
15# Instantiate SimpleElastix
16elastix_image_filter = sitk.ElastixImageFilter()
17
18# Read input images
19fixed_image = sitk.ReadImage(sys.argv[1])
20moving_image = sitk.ReadImage(sys.argv[2])
21
22# Set images
23elastix_image_filter.SetFixedImage(fixed_image)
24elastix_image_filter.SetMovingImage(moving_image)
25
26# Read and set parameter map
27parameter_map = sitk.ReadParameterFile(sys.argv[3])
28elastix_image_filter.SetParameterMap(parameter_map)
29
30# Enable logging to console
31elastix_image_filter.LogToConsoleOn()
32
33# Run registration
34elastix_image_filter.Execute()
35
36# Write result image
37sitk.WriteImage(elastix_image_filter.GetResultImage(), sys.argv[4])
38
39# Write parameter file
40# This example only supports one parameter map and one transform parameter map
41sitk.WriteParameterFile(elastix_image_filter.GetTransformParameterMaps()[0], sys.argv[5])
The class that wraps the elastix registration library.
SITKIO_EXPORT Image ReadImage(const PathType &filename, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageFileReader class which is convenient for most image r...
SITKIO_EXPORT void WriteImage(const Image &image, const PathType &fileName, bool useCompression=false, int compressionLevel=-1)
WriteImage is a procedural interface to the ImageFileWriter. class which is convenient for many image...
SITKElastix_EXPORT std::map< std::string, std::vector< std::string > > ReadParameterFile(const std::string filename)
SITKElastix_EXPORT void WriteParameterFile(const std::map< std::string, std::vector< std::string > > parameterMap, const std::string filename)