SimpleITK  
Elastix/ParameterMaps/ParameterMaps.cxx
#include "SimpleITK.h"
#include <iostream>
#include <string>
namespace sitk = itk::simple;
int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " <fixedImage> <movingImage> [outputPrefix]" << std::endl;
return 1;
}
// Read input images
sitk::Image fixedImage = sitk::ReadImage(argv[1]);
sitk::Image movingImage = sitk::ReadImage(argv[2]);
std::cout << "SimpleITK Elastix Parameter Maps Example" << std::endl;
std::cout << std::string(60, '=') << std::endl;
// START_DEFAULT_PARAMETER_MAP
// Get a default parameter map for a common registration type
// Print parameter map to see its contents
sitk::PrintParameterMap(parameterMap);
// END_DEFAULT_PARAMETER_MAP
// START_MODIFY_PARAMETER_MAP
// Modify parameter map entries (values are vectors of strings)
parameterMap["Transform"] = sitk::ElastixImageFilter::ParameterValueVectorType(1, "AffineTransform");
parameterMap["MaximumNumberOfIterations"] = sitk::ElastixImageFilter::ParameterValueVectorType(1, "512");
parameterMap["NumberOfSpatialSamples"] = sitk::ElastixImageFilter::ParameterValueVectorType(1, "8192");
// END_MODIFY_PARAMETER_MAP
// START_MULTI_STAGE_REGISTRATION
// Multi-stage registration: translation -> affine -> bspline
sitk::ElastixImageFilter elastixImageFilter;
elastixImageFilter.SetFixedImage(fixedImage);
elastixImageFilter.SetMovingImage(movingImage);
elastixImageFilter.SetParameterMap(sitk::GetDefaultParameterMap("translation"));
elastixImageFilter.AddParameterMap(sitk::GetDefaultParameterMap("affine"));
bsplineMap["FinalGridSpacingInPhysicalUnits"] = sitk::ElastixImageFilter::ParameterValueVectorType(1, "8.0");
elastixImageFilter.AddParameterMap(bsplineMap);
elastixImageFilter.LogToConsoleOff();
sitk::Image resultImage = elastixImageFilter.Execute();
// Retrieve transform parameter maps from the result
elastixImageFilter.GetTransformParameterMaps();
// END_MULTI_STAGE_REGISTRATION
// START_READ_WRITE_PARAMETER_MAP
// Write a parameter map to a file
sitk::WriteParameterFile(parameterMap, "parameters.txt");
// Read a parameter map from a file
// END_READ_WRITE_PARAMETER_MAP
// Write results if output prefix provided
if (argc > 3)
{
std::string outputPrefix = argv[3];
for (size_t i = 0; i < transformParameterMaps.size(); ++i)
{
std::string filename = outputPrefix + "_TransformParameters_" + std::to_string(i) + ".txt";
sitk::WriteParameterFile(transformParameterMaps[i], filename);
}
sitk::WriteImage(resultImage, outputPrefix + ".nii");
}
return 0;
}
The class that wraps the elastix registration library.
void SetParameterMap(const std::string transformName, const unsigned int numberOfResolutions=4u, const double finalGridSpacingInPhysicalUnits=10.0)
Specifies the parameter map by a transformName ("translation", "rigid" , "affine",...
std::vector< ParameterMapType > ParameterMapVectorType
std::map< ParameterKeyType, ParameterValueVectorType > ParameterMapType
void AddParameterMap(const std::map< std::string, std::vector< std::string > > parameterMap)
Adds a parameter map to the container of parameter maps.
void SetFixedImage(const Image &fixedImage)
Sets a fixed image. Stores the image into the container of fixed images.
void SetMovingImage(const Image &movingImages)
Sets a moving image. Stores the image into the container of moving images.
void LogToConsoleOff()
Switches logging to console off.
std::vector< ParameterValueType > ParameterValueVectorType
std::vector< std::map< std::string, std::vector< std::string > > > GetTransformParameterMaps()
Returns all transform parameter maps.
Image Execute()
Executes the registration, and returns the result image.
The Image class for SimpleITK.
Definition sitkImage.h:77
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...
SITKElastix_EXPORT std::map< std::string, std::vector< std::string > > GetDefaultParameterMap(const std::string transform, const unsigned int numberOfResolutions=4, const double finalGridSpacingInPhysicalUnits=8.0)
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 void PrintParameterMap(const std::map< std::string, std::vector< std::string > > parameterMap)
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)