SimpleITK  
sitkElastixImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef sitkElastixImageFilter_h
19#define sitkElastixImageFilter_h
20
22#include "sitkCommon.h"
23#include "sitkImage.h"
24
25#include <map>
26#include <memory> // For unique_ptr.
27#include <string>
28#include <vector>
29
30namespace itk::simple
31{
32
37{
38public:
41
44
46
47 typedef std::vector<Image> VectorOfImage;
48
49 typedef std::string ParameterKeyType;
50 typedef std::string ParameterValueType;
51 typedef std::vector<ParameterValueType> ParameterValueVectorType;
52 typedef ParameterValueVectorType::iterator ParameterValueVectorIterator;
53 typedef std::map<ParameterKeyType, ParameterValueVectorType> ParameterMapType;
54 typedef std::vector<ParameterMapType> ParameterMapVectorType;
55 typedef ParameterMapType::iterator ParameterMapIterator;
56 typedef ParameterMapType::const_iterator ParameterMapConstIterator;
57
58 std::string
59 GetName() const;
60
62 SITK_RETURN_SELF_TYPE_HEADER
63 SetFixedImage(const Image & fixedImage);
64
66 SITK_RETURN_SELF_TYPE_HEADER
67 SetFixedImage(const VectorOfImage & fixedImages);
68
70 SITK_RETURN_SELF_TYPE_HEADER
71 AddFixedImage(const Image & fixedImage);
72
74 Image &
75 GetFixedImage(const unsigned long index);
76
80
82 SITK_RETURN_SELF_TYPE_HEADER
83 RemoveFixedImage(const unsigned long index);
84
86 SITK_RETURN_SELF_TYPE_HEADER
88
90 unsigned int
92
94 SITK_RETURN_SELF_TYPE_HEADER
95 SetMovingImage(const Image & movingImages);
96
98 SITK_RETURN_SELF_TYPE_HEADER
99 SetMovingImage(const VectorOfImage & movingImage);
100
102 SITK_RETURN_SELF_TYPE_HEADER
103 AddMovingImage(const Image & movingImage);
104
106 Image &
107 GetMovingImage(const unsigned long index);
108
112
114 SITK_RETURN_SELF_TYPE_HEADER
115 RemoveMovingImage(const unsigned long index);
116
118 SITK_RETURN_SELF_TYPE_HEADER
120
122 unsigned int
124
126 SITK_RETURN_SELF_TYPE_HEADER
127 SetFixedMask(const Image & fixedMask);
128
130 SITK_RETURN_SELF_TYPE_HEADER
131 SetFixedMask(const VectorOfImage & fixedMasks);
132
134 SITK_RETURN_SELF_TYPE_HEADER
135 AddFixedMask(const Image & fixedMask);
136
138 Image &
139 GetFixedMask(const unsigned long index);
140
144
146 SITK_RETURN_SELF_TYPE_HEADER
147 RemoveFixedMask(const unsigned long index);
148
150 SITK_RETURN_SELF_TYPE_HEADER
152
154 unsigned int
156
158 SITK_RETURN_SELF_TYPE_HEADER
159 SetMovingMask(const Image & movingMask);
160
162 SITK_RETURN_SELF_TYPE_HEADER
163 SetMovingMask(const VectorOfImage & movingMasks);
164
166 SITK_RETURN_SELF_TYPE_HEADER
167 AddMovingMask(const Image & movingMask);
168
170 Image &
171 GetMovingMask(const unsigned long index);
172
176
178 SITK_RETURN_SELF_TYPE_HEADER
179 RemoveMovingMask(const unsigned long index);
180
182 SITK_RETURN_SELF_TYPE_HEADER
184
186 unsigned int
188
190 SITK_RETURN_SELF_TYPE_HEADER
191 SetFixedPointSetFileName(const std::string fixedPointSetFileName);
192
194 std::string
196
198 SITK_RETURN_SELF_TYPE_HEADER
200
202 SITK_RETURN_SELF_TYPE_HEADER
203 SetMovingPointSetFileName(const std::string movingPointSetFileName);
204
206 std::string
208
210 SITK_RETURN_SELF_TYPE_HEADER
212
214 SITK_RETURN_SELF_TYPE_HEADER
215 SetOutputDirectory(const std::string outputDirectory);
216
218 std::string
220
222 SITK_RETURN_SELF_TYPE_HEADER
224
226 SITK_RETURN_SELF_TYPE_HEADER
227 SetLogFileName(const std::string logFileName);
228
230 std::string
232
234 SITK_RETURN_SELF_TYPE_HEADER
236
238 SITK_RETURN_SELF_TYPE_HEADER
239 SetLogToFile(const bool logToFile);
240
242 bool
244
246 SITK_RETURN_SELF_TYPE_HEADER
248
250 SITK_RETURN_SELF_TYPE_HEADER
252
254 SITK_RETURN_SELF_TYPE_HEADER
256
258 bool
260
262 SITK_RETURN_SELF_TYPE_HEADER
264
266 SITK_RETURN_SELF_TYPE_HEADER
268
272 SITK_RETURN_SELF_TYPE_HEADER
274
276 int
278
281 SITK_RETURN_SELF_TYPE_HEADER
282 SetParameterMap(const std::string transformName,
283 const unsigned int numberOfResolutions = 4u,
284 const double finalGridSpacingInPhysicalUnits = 10.0);
285
287 SITK_RETURN_SELF_TYPE_HEADER
288 SetParameterMap(const std::vector<std::map<std::string, std::vector<std::string>>> parameterMapVector);
289 SITK_RETURN_SELF_TYPE_HEADER
290 SetParameterMaps(const std::vector<std::map<std::string, std::vector<std::string>>> parameterMapVector)
291 {
292 return SetParameterMap(parameterMapVector);
293 }
294
296 SITK_RETURN_SELF_TYPE_HEADER
297 SetParameterMap(const std::map<std::string, std::vector<std::string>> parameterMap);
298
300 SITK_RETURN_SELF_TYPE_HEADER
301 AddParameterMap(const std::map<std::string, std::vector<std::string>> parameterMap);
302
304 std::vector<std::map<std::string, std::vector<std::string>>>
306 std::vector<std::map<std::string, std::vector<std::string>>>
308 {
309 return GetParameterMap();
310 };
311
314 std::map<std::string, std::vector<std::string>>
315 GetDefaultParameterMap(const std::string transformName,
316 const unsigned int numberOfResolutions = 4,
317 const double finalGridSpacingInPhysicalUnits = 10.0);
318
320 unsigned int
322
324 SITK_RETURN_SELF_TYPE_HEADER
325 SetParameter(const std::string key, const std::string value);
326
328 SITK_RETURN_SELF_TYPE_HEADER
329 SetParameter(const std::string key, const std::vector<std::string> value);
330
333 SITK_RETURN_SELF_TYPE_HEADER
334 SetParameter(const unsigned int index, const std::string key, const std::string value);
335
338 SITK_RETURN_SELF_TYPE_HEADER
339 SetParameter(const unsigned int index, const std::string key, const std::vector<std::string> value);
340
342 SITK_RETURN_SELF_TYPE_HEADER
343 AddParameter(const std::string key, const std::string value);
344
347 SITK_RETURN_SELF_TYPE_HEADER
348 AddParameter(const unsigned int index, const std::string key, const std::string value);
349
351 SITK_RETURN_SELF_TYPE_HEADER
352 AddParameter(const std::string key, const std::vector<std::string> value);
353
356 SITK_RETURN_SELF_TYPE_HEADER
357 AddParameter(const unsigned int index, const std::string key, const std::vector<std::string> value);
358
360 std::vector<std::string>
361 GetParameter(const std::string key);
362
365 std::vector<std::string>
366 GetParameter(const unsigned int index, const std::string key);
367
369 SITK_RETURN_SELF_TYPE_HEADER
370 RemoveParameter(const std::string key);
371
373 SITK_RETURN_SELF_TYPE_HEADER
374 RemoveParameter(const unsigned int index, const std::string key);
375
377 SITK_RETURN_SELF_TYPE_HEADER
378 SetInitialTransformParameterFileName(const std::string initialTransformParmaterFileName);
379
381 std::string
383
385 SITK_RETURN_SELF_TYPE_HEADER
387
389 std::map<std::string, std::vector<std::string>>
390 ReadParameterFile(const std::string filename);
391
393 SITK_RETURN_SELF_TYPE_HEADER
394 WriteParameterFile(const std::map<std::string, std::vector<std::string>> parameterMap, const std::string filename);
395
401 Image
403
405 std::vector<std::map<std::string, std::vector<std::string>>>
407
409 std::map<std::string, std::vector<std::string>>
410 GetTransformParameterMap(const unsigned int index);
411
413 Image
415
417 SITK_RETURN_SELF_TYPE_HEADER
419
421 SITK_RETURN_SELF_TYPE_HEADER
422 PrintParameterMap(const ParameterMapType parameterMapVector);
423
425 SITK_RETURN_SELF_TYPE_HEADER
426 PrintParameterMap(const ParameterMapVectorType parameterMapVector);
427
428private:
430 const std::unique_ptr<ElastixImageFilterImpl> m_Pimple;
431};
432
433// Procedural Interface
434SITKElastix_EXPORT std::map<std::string, std::vector<std::string>>
435 GetDefaultParameterMap(const std::string transform,
436 const unsigned int numberOfResolutions = 4,
437 const double finalGridSpacingInPhysicalUnits = 8.0);
438SITKElastix_EXPORT std::map<std::string, std::vector<std::string>>
439 ReadParameterFile(const std::string filename);
441WriteParameterFile(const std::map<std::string, std::vector<std::string>> parameterMap, const std::string filename);
443PrintParameterMap(const std::map<std::string, std::vector<std::string>> parameterMap);
445PrintParameterMap(const std::vector<std::map<std::string, std::vector<std::string>>> parameterMapVector);
447Elastix(const Image & fixedImage,
448 const Image & movingImage,
449 const bool logToConsole = false,
450 const bool logToFile = false,
451 const std::string outputDirectory = ".");
453Elastix(const Image & fixedImage,
454 const Image & movingImage,
455 const Image & fixedMask,
456 const Image & movingMask,
457 const bool logToConsole = false,
458 const bool logToFile = false,
459 const std::string outputDirectory = ".");
461Elastix(const Image & fixedImage,
462 const Image & movingImage,
463 const std::string defaultParameterMapName,
464 const bool logToConsole = false,
465 const bool logToFile = false,
466 const std::string outputDirectory = ".");
468Elastix(const Image & fixedImage,
469 const Image & movingImage,
470 const std::map<std::string, std::vector<std::string>> parameterMap,
471 const bool logToConsole = false,
472 const bool logToFile = false,
473 const std::string outputDirectory = ".");
475Elastix(const Image & fixedImage,
476 const Image & movingImage,
477 const std::vector<std::map<std::string, std::vector<std::string>>> parameterMapVector,
478 const bool logToConsole = false,
479 const bool logToFile = false,
480 const std::string outputDirectory = ".");
482Elastix(const Image & fixedImage,
483 const Image & movingImage,
484 const std::string defaultParameterMapName,
485 const Image & fixedMask,
486 const Image & movingMask,
487 const bool logToConsole = false,
488 const bool logToFile = false,
489 const std::string outputDirectory = ".");
491Elastix(const Image & fixedImage,
492 const Image & movingImage,
493 const std::map<std::string, std::vector<std::string>>,
494 const Image & fixedMask,
495 const Image & movingMask,
496 const bool logToConsole = false,
497 const bool logToFile = false,
498 const std::string outputDirectory = ".");
500Elastix(const Image & fixedImage,
501 const Image & movingImage,
502 std::vector<std::map<std::string, std::vector<std::string>>> parameterMapVector,
503 const Image & fixedMask,
504 const Image & movingMask,
505 const bool logToConsole = false,
506 const bool logToFile = false,
507 const std::string outputDirectory = ".");
508
509} // namespace itk::simple
510
511#endif // sitkElastixImageFilter_h
Self & AddParameter(const std::string key, const std::string value)
Adds a parameter specified by key, with the specified value to all parameter maps.
Self & SetLogToFile(const bool logToFile)
Switches logging to file on (true) or off (false), as specified by its function argument.
Self & SetMovingPointSetFileName(const std::string movingPointSetFileName)
Specifies a set of points from the moving image by a point set file, movingPointSetFileName.
std::vector< std::map< std::string, std::vector< std::string > > > GetTransformParameterMap()
Returns all transform parameter maps.
Self & SetInitialTransformParameterFileName(const std::string initialTransformParmaterFileName)
Specifies the initial transformation by the specified transform parameter file name.
Self & SetParameter(const unsigned int index, const std::string key, const std::vector< std::string > value)
Sets the values of the parameter specified by key, in the parameter map at the specified (zero-based)...
Image & GetMovingImage(const unsigned long index)
Retrieves a reference to the moving image at the specified (zero-based) index.
std::string GetOutputDirectory()
Returns the current output directory.
Self & SetParameterMap(const std::map< std::string, std::vector< std::string > > parameterMap)
Specifies a single parameter map.
std::vector< std::string > GetParameter(const std::string key)
Retrieves the values of the parameter specified by key, when there is only one parameter map.
Self & LogToConsoleOn()
Switches logging to console on.
Self & SetFixedMask(const Image &fixedMask)
Sets a fixed mask. Stores the image into the container of fixed masks.
bool GetLogToConsole()
Returns whether logging to console is switched on.
std::string GetLogFileName()
Returns the name of the current log file.
Self & SetOutputDirectory(const std::string outputDirectory)
Sets the output directory.
Self & RemoveFixedImage()
Removes all fixed images.
Self & RemoveMovingMask()
Removes all moving masks.
Image & GetMovingMask(const unsigned long index)
Retrieves a reference to the moving mask at the specified (zero-based) index.
Self & SetNumberOfThreads(int n)
Sets the maximum number of threads to the specified number n.
unsigned int GetNumberOfParameterMaps()
Returns the number of parameter maps.
std::string GetFixedPointSetFileName()
Returns the name of the current point set file of points from the fixed image.
unsigned int GetNumberOfFixedMasks()
Returns the number of fixed masks.
Self & SetParameter(const unsigned int index, const std::string key, const std::string value)
Sets the value of the parameter specified by key, in the parameter map at the specified (zero-based) ...
ParameterMapType::const_iterator ParameterMapConstIterator
std::vector< std::string > GetParameter(const unsigned int index, const std::string key)
Retrieves the values of the parameter specified by key, from the parameter map at the specified (zero...
Self & AddParameter(const unsigned int index, const std::string key, const std::string value)
Adds a parameter specified by key, with the specified value to the parameter map at the specified (ze...
Self & RemoveFixedMask()
Removes all fixed masks.
Self & RemoveInitialTransformParameterFileName()
Clears the initial transform parameter file name.
bool GetLogToFile()
Returns whether logging to file is switched on.
Image & GetFixedMask(const unsigned long index)
Retrieves a reference to the fixed mask at the specified (zero-based) index.
Self & AddMovingImage(const Image &movingImage)
Adds an image to the end of the container of moving images.
Self & SetParameterMaps(const std::vector< std::map< std::string, std::vector< std::string > > > parameterMapVector)
Self & PrintParameterMap()
Prints all parameter maps to standard output.
Self & RemoveMovingPointSetFileName()
Clears the current point set file name of points from the moving image.
Image & GetFixedImage(const unsigned long index)
Retrieves a reference to the fixed image at the specified (zero-based) index.
Self & SetLogToConsole(bool)
Switches logging to console on (true) or off (false), as specified by its function argument.
Self & LogToFileOff()
Switches logging to file off.
VectorOfImage & GetMovingImage()
Retrieves a reference to the moving image at the specified (zero-based) index.
Self & SetParameterMap(const std::vector< std::map< std::string, std::vector< std::string > > > parameterMapVector)
Specifies multiple parameter maps.
VectorOfImage & GetMovingMask()
Retrieves a reference to the container of moving masks.
Self & SetMovingImage(const VectorOfImage &movingImage)
Sets multiple moving images. Stores the images into the container of moving images.
std::map< std::string, std::vector< std::string > > ReadParameterFile(const std::string filename)
Reads the parameter file specified by filename, and returns its content as a parameter map.
int GetNumberOfThreads()
Returns the current maximum number of threads.
Self & LogToFileOn()
Switches logging to file on.
std::vector< ParameterMapType > ParameterMapVectorType
std::map< std::string, std::vector< std::string > > GetTransformParameterMap(const unsigned int index)
Returns the transform parameter map at the specified (zero-based) index.
Self & AddParameter(const unsigned int index, const std::string key, const std::vector< std::string > value)
Adds a parameter specified by key, with the specified values to the parameter map at the specified (z...
Self & SetMovingMask(const Image &movingMask)
Sets a moving mask. Stores the image into the container of moving masks.
Self & RemoveMovingImage()
Removes all moving images.
std::map< ParameterKeyType, ParameterValueVectorType > ParameterMapType
Self & RemoveMovingImage(const unsigned long index)
Removes an image at the specified (zero-based) index from the container of moving images.
std::string GetMovingPointSetFileName()
Returns the name of the current point set file of points from the moving image.
unsigned int GetNumberOfMovingImages()
Returns the number of moving images.
std::vector< std::map< std::string, std::vector< std::string > > > GetParameterMap()
Returns a copy of the parameter maps.
Self & SetFixedImage(const VectorOfImage &fixedImages)
Sets multiple fixed images. Stores the images into the container of fixed images.
Self & AddParameter(const std::string key, const std::vector< std::string > value)
Adds a parameter specified by key, with the specified values to all parameter maps.
Self & SetFixedPointSetFileName(const std::string fixedPointSetFileName)
Specifies a set of points from the fixed image by a point set file, fixedPointSetFileName.
Self & PrintParameterMap(const ParameterMapType parameterMapVector)
Prints the specified parameter map to standard output.
ParameterValueVectorType::iterator ParameterValueVectorIterator
VectorOfImage & GetFixedImage()
Retrieves a reference to the container of fixed images.
Self & RemoveFixedImage(const unsigned long index)
Removes an image at the specified (zero-based) index from the container of fixed images.
Self & SetLogFileName(const std::string logFileName)
Sets the name of the current log file.
unsigned int GetNumberOfMovingMasks()
Returns the number of moving masks.
VectorOfImage & GetFixedMask()
Retrieves a reference to the container of fixed masks.
Self & RemoveLogFileName()
Clears the name of the current log file.
Self & SetParameter(const std::string key, const std::vector< std::string > value)
Sets the values of the parameter specified by key, in all parameter maps.
Self & LogToConsoleOff()
Switches logging to console off.
Self & 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",...
Self & RemoveParameter(const unsigned int index, const std::string key)
Removes the parameter specified by key from the parameter map at the specified (zero-based) index.
std::vector< ParameterValueType > ParameterValueVectorType
std::map< std::string, std::vector< std::string > > GetDefaultParameterMap(const std::string transformName, const unsigned int numberOfResolutions=4, const double finalGridSpacingInPhysicalUnits=10.0)
Returns the default parameter map for the specified function arguments (transformName may be "transla...
Self & PrintParameterMap(const ParameterMapVectorType parameterMapVector)
Prints the specified parameter maps to standard output.
Self & RemoveMovingMask(const unsigned long index)
Removes an image at the specified (zero-based) index from the container of moving masks.
Self & WriteParameterFile(const std::map< std::string, std::vector< std::string > > parameterMap, const std::string filename)
Writes a parameter map to the file, specified by filename.
std::string GetName() const
std::string GetInitialTransformParameterFileName()
Returns the initial transform parameter file name.
unsigned int GetNumberOfFixedImages()
Returns the number of fixed images.
Self & AddFixedMask(const Image &fixedMask)
Adds an image to the end of the container of fixed masks.
Self & AddFixedImage(const Image &fixedImage)
Adds an image to the end of the container of fixed images.
Self & AddParameterMap(const std::map< std::string, std::vector< std::string > > parameterMap)
Adds a parameter map to the container of parameter maps.
const std::unique_ptr< ElastixImageFilterImpl > m_Pimple
Self & SetParameter(const std::string key, const std::string value)
Sets the value of the parameter specified by key, in all parameter maps.
Self & SetFixedImage(const Image &fixedImage)
Sets a fixed image. Stores the image into the container of fixed images.
Self & SetMovingImage(const Image &movingImages)
Sets a moving image. Stores the image into the container of moving images.
Self & AddMovingMask(const Image &movingMask)
Adds an image to the end of the container of moving masks.
Image GetResultImage()
Returns the result image.
Self & SetMovingMask(const VectorOfImage &movingMasks)
Sets multiple moving masks. Stores the images into the container of moving masks.
Self & RemoveFixedPointSetFileName()
Clears the current point set file name of points from the fixed image.
std::vector< std::map< std::string, std::vector< std::string > > > GetParameterMaps()
Self & RemoveFixedMask(const unsigned long index)
Removes an image at the specified (zero-based) index from the container of fixed masks.
Self & RemoveOutputDirectory()
Clears the name of the current output directory. (Does not remove the actual directory....
ElastixImageFilter()
Default-constructor.
ParameterMapType::iterator ParameterMapIterator
Image Execute()
Executes the registration, and returns the result image.
Self & RemoveParameter(const std::string key)
Removes the parameter specified by key from all parameter maps.
Self & SetFixedMask(const VectorOfImage &fixedMasks)
Sets multiple fixed masks. Stores the images into the container of fixed masks.
The Image class for SimpleITK.
Definition sitkImage.h:77
SITKElastix_EXPORT Image Elastix(const Image &fixedImage, const Image &movingImage, const bool logToConsole=false, const bool logToFile=false, const std::string outputDirectory=".")
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)
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)
#define SITKElastix_EXPORT