19 #include "itkImageFileWriter.h"
20 #include "itkWarpImageFilter.h"
22 #include "itkInverseDisplacementFieldImageFilter.h"
30 m_StandardDeviation(1.0),
31 m_FieldName(
"newField.mhd"),
32 m_ResultName(
"deformedImage.mhd"),
35 m_DeformationField(nullptr)
55 template <
typename TPixel,
unsigned int VImageDimension>
58 typedef typename itk::Image<TPixel, VImageDimension> FixedImageType;
59 typedef typename itk::Image<TPixel, VImageDimension> MovingImageType;
61 typedef float InternalPixelType;
62 typedef typename itk::Image<InternalPixelType, VImageDimension> InternalImageType;
63 typedef typename itk::CastImageFilter<FixedImageType, InternalImageType> FixedImageCasterType;
64 typedef typename itk::CastImageFilter<MovingImageType, InternalImageType> MovingImageCasterType;
65 typedef typename itk::Vector<float, VImageDimension> VectorPixelType;
68 typename itk::SymmetricForcesDemonsRegistrationFilter<InternalImageType, InternalImageType, DeformationFieldType>
69 RegistrationFilterType;
70 typedef typename itk::WarpImageFilter<MovingImageType, MovingImageType, DeformationFieldType> WarperType;
71 typedef typename itk::LinearInterpolateImageFunction<MovingImageType, double> InterpolatorType;
73 typedef TPixel OutputPixelType;
74 typedef typename itk::Image<OutputPixelType, VImageDimension>
OutputImageType;
75 typedef typename itk::CastImageFilter<MovingImageType, OutputImageType> CastFilterType;
76 typedef typename itk::ImageFileWriter<OutputImageType> WriterType;
77 typedef typename itk::ImageFileWriter<DeformationFieldType> FieldWriterType;
83 if (fixedImage.IsNotNull() && movingImage.IsNotNull())
91 filter->AddObserver(itk::IterationEvent(), command);
94 fixedImageCaster->SetInput(fixedImage);
95 filter->SetFixedImage(fixedImageCaster->GetOutput());
97 movingImageCaster->SetInput(movingImage);
98 filter->SetMovingImage(movingImageCaster->GetOutput());
106 warper->SetInput(movingImage);
107 warper->SetInterpolator(interpolator);
108 warper->SetOutputSpacing(fixedImage->GetSpacing());
109 warper->SetOutputOrigin(fixedImage->GetOrigin());
110 warper->SetDisplacementField(filter->GetOutput());
117 caster->SetInput(warper->GetOutput());
118 writer->SetInput(caster->GetOutput());
126 if (VImageDimension == 2)
128 typedef DeformationFieldType VectorImage2DType;
133 typename VectorImage2DType::RegionType region2D = vectorImage2D->GetBufferedRegion();
134 typename VectorImage2DType::IndexType index2D = region2D.GetIndex();
135 typename VectorImage2DType::SizeType size2D = region2D.GetSize();
137 typedef typename itk::Vector<float, 3> Vector3DType;
138 typedef typename itk::Image<Vector3DType, 3> VectorImage3DType;
140 typedef typename itk::ImageFileWriter<VectorImage3DType> WriterType;
146 VectorImage3DType::RegionType region3D;
147 VectorImage3DType::IndexType index3D;
148 VectorImage3DType::SizeType size3D;
150 index3D[0] = index2D[0];
151 index3D[1] = index2D[1];
154 size3D[0] = size2D[0];
155 size3D[1] = size2D[1];
158 region3D.SetSize(size3D);
159 region3D.SetIndex(index3D);
161 typename VectorImage2DType::SpacingType spacing2D = vectorImage2D->GetSpacing();
162 VectorImage3DType::SpacingType spacing3D;
164 spacing3D[0] = spacing2D[0];
165 spacing3D[1] = spacing2D[1];
168 vectorImage3D->SetSpacing(spacing3D);
170 vectorImage3D->SetRegions(region3D);
171 vectorImage3D->Allocate();
173 typedef typename itk::ImageRegionConstIterator<VectorImage2DType> Iterator2DType;
175 typedef typename itk::ImageRegionIterator<VectorImage3DType> Iterator3DType;
177 Iterator2DType it2(vectorImage2D, region2D);
178 Iterator3DType it3(vectorImage3D, region3D);
183 Vector2DType vector2D;
184 Vector3DType vector3D;
188 while (!it2.IsAtEnd())
190 vector2D = it2.Get();
191 vector3D[0] = vector2D[0];
192 vector3D[1] = vector2D[1];
198 writer3D->SetInput(vectorImage3D);
210 catch (itk::ExceptionObject &excp)
219 fieldwriter->SetInput(filter->GetOutput());
224 fieldwriter->Update();
itk::SmartPointer< Self > Pointer
void SetSaveDeformationField(bool saveField)
Sets whether the resulting deformation field should be saved or not.
void SetSaveResult(bool saveResult)
Sets whether the result should be saved or not.
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetRemainingProgress(int steps)
Sets the remaining progress to the progress bar.
void SetResultFileName(const char *resultName)
Sets the filename for the resulting deformed image.
itk::SmartPointer< const Self > ConstPointer
SymmetricForcesDemonsRegistration()
Default constructor.
virtual void AddStepsToDo(int steps)
Adds steps to the progress bar, which will be done with AddStepsToDo(int steps) and SetRemainingProgr...
virtual void SetProgress(const itk::EventObject &)
Sets one step of progress to the progress bar.
void SetStandardDeviation(float deviation)
Sets the standard deviation used by the symmetric forces demons registration.
Image::Pointer m_ReferenceImage
mitk::Image OutputImageType
Some convenient typedefs.
void GenerateData2(const itk::Image< TPixel, VImageDimension > *itkImage1)
Template class to perform the symmetric forces demons registration with any kind of image...
itk::Image< VectorType, 3 > DeformationFieldType
const char * m_ResultName
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
void SetNumberOfIterations(int iterations)
Sets the number of iterations which will be performed during the registration process.
itk::Image< class itk::Vector< float, 3 >, 3 >::Pointer GetDeformationField()
Returns the deformation field, which results by the registration.
virtual ~SymmetricForcesDemonsRegistration()
Default destructor.
OutputType * GetOutput()
Get the output data of this image source object.
itk::Image< class itk::Vector< float, 3 >, 3 >::Pointer m_DeformationField
float m_StandardDeviation
void SetDeformationFieldFileName(const char *fieldName)
Sets the filename for the resulting deformation field.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.