19 #include "itkImageFileWriter.h"
20 #include "itkImageRegionIterator.h"
21 #include "itkWarpImageFilter.h"
29 m_StandardDeviation(1.0),
30 m_FieldName(
"newField.mhd"),
31 m_ResultName(
"deformedImage.mhd"),
34 m_DeformationField(nullptr)
46 template <
typename TPixel,
unsigned int VImageDimension>
49 typedef typename itk::Image<TPixel, VImageDimension> FixedImageType;
50 typedef typename itk::Image<TPixel, VImageDimension> MovingImageType;
52 typedef float InternalPixelType;
53 typedef typename itk::Image<InternalPixelType, VImageDimension> InternalImageType;
54 typedef typename itk::CastImageFilter<FixedImageType, InternalImageType> FixedImageCasterType;
55 typedef typename itk::CastImageFilter<MovingImageType, InternalImageType> MovingImageCasterType;
56 typedef typename itk::Image<InternalPixelType, VImageDimension> InternalImageType;
57 typedef typename itk::Vector<float, VImageDimension> VectorPixelType;
59 typedef typename itk::DemonsRegistrationFilter<InternalImageType, InternalImageType, DeformationFieldType>
60 RegistrationFilterType;
61 typedef typename itk::WarpImageFilter<MovingImageType, MovingImageType, DeformationFieldType> WarperType;
62 typedef typename itk::LinearInterpolateImageFunction<MovingImageType, double> InterpolatorType;
64 typedef TPixel OutputPixelType;
65 typedef typename itk::Image<OutputPixelType, VImageDimension>
OutputImageType;
66 typedef typename itk::CastImageFilter<MovingImageType, OutputImageType> CastFilterType;
67 typedef typename itk::ImageFileWriter<OutputImageType> WriterType;
68 typedef typename itk::ImageFileWriter<DeformationFieldType> FieldWriterType;
74 if (fixedImage.IsNotNull() && movingImage.IsNotNull())
82 filter->AddObserver(itk::IterationEvent(), command);
85 fixedImageCaster->SetInput(fixedImage);
86 filter->SetFixedImage(fixedImageCaster->GetOutput());
88 movingImageCaster->SetInput(movingImage);
89 filter->SetMovingImage(movingImageCaster->GetOutput());
97 warper->SetInput(movingImage);
98 warper->SetInterpolator(interpolator);
99 warper->SetOutputSpacing(fixedImage->GetSpacing());
100 warper->SetOutputOrigin(fixedImage->GetOrigin());
101 warper->SetOutputDirection(fixedImage->GetDirection());
102 warper->SetDisplacementField(filter->GetOutput());
112 caster->SetInput(warper->GetOutput());
113 writer->SetInput(caster->GetOutput());
119 if (VImageDimension == 2)
121 typedef DeformationFieldType VectorImage2DType;
126 typename VectorImage2DType::RegionType region2D = vectorImage2D->GetBufferedRegion();
127 typename VectorImage2DType::IndexType index2D = region2D.GetIndex();
128 typename VectorImage2DType::SizeType size2D = region2D.GetSize();
130 typedef typename itk::Vector<float, 3> Vector3DType;
131 typedef typename itk::Image<Vector3DType, 3> VectorImage3DType;
133 typedef typename itk::ImageFileWriter<VectorImage3DType> WriterType;
139 typename VectorImage3DType::RegionType region3D;
140 typename VectorImage3DType::IndexType index3D;
141 typename VectorImage3DType::SizeType size3D;
143 index3D[0] = index2D[0];
144 index3D[1] = index2D[1];
147 size3D[0] = size2D[0];
148 size3D[1] = size2D[1];
151 region3D.SetSize(size3D);
152 region3D.SetIndex(index3D);
154 typename VectorImage2DType::SpacingType spacing2D = vectorImage2D->GetSpacing();
155 typename VectorImage3DType::SpacingType spacing3D;
157 spacing3D[0] = spacing2D[0];
158 spacing3D[1] = spacing2D[1];
161 vectorImage3D->SetSpacing(spacing3D);
163 vectorImage3D->SetRegions(region3D);
164 vectorImage3D->Allocate();
166 typedef typename itk::ImageRegionConstIterator<VectorImage2DType> Iterator2DType;
168 typedef typename itk::ImageRegionIterator<VectorImage3DType> Iterator3DType;
170 Iterator2DType it2(vectorImage2D, region2D);
171 Iterator3DType it3(vectorImage3D, region3D);
176 Vector2DType vector2D;
177 Vector3DType vector3D;
181 while (!it2.IsAtEnd())
183 vector2D = it2.Get();
184 vector3D[0] = vector2D[0];
185 vector3D[1] = vector2D[1];
191 writer3D->SetInput(vectorImage3D);
203 catch (itk::ExceptionObject &excp)
212 fieldwriter->SetInput(filter->GetOutput());
216 fieldwriter->Update();
void SetSaveResult(bool saveResult)
Sets whether the result should be saved or not.
itk::SmartPointer< Self > Pointer
void SetDeformationFieldFileName(const char *fieldName)
Sets the filename for the resulting deformation field.
void SetNumberOfIterations(int iterations)
Sets the number of iterations which will be performed during the registration process.
DemonsRegistration()
Default constructor.
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetRemainingProgress(int steps)
Sets the remaining progress to the progress bar.
itk::SmartPointer< const Self > ConstPointer
void SetStandardDeviation(float deviation)
Sets the standard deviation used by the demons registration.
void SetResultFileName(const char *resultName)
Sets the filename for the resulting deformed image.
void SetSaveDeformationField(bool saveField)
Sets whether the resulting deformation field should be saved or not.
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.
itk::Image< itk::Vector< float, 3 >, 3 >::Pointer GetDeformationField()
Returns the deformation field, which results by the registration.
float m_StandardDeviation
itk::Image< class itk::Vector< float, 3 >, 3 >::Pointer m_DeformationField
Image::Pointer m_ReferenceImage
mitk::Image OutputImageType
Some convenient typedefs.
const char * m_ResultName
itk::Image< VectorType, 3 > DeformationFieldType
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.
OutputType * GetOutput()
Get the output data of this image source object.
void GenerateData2(const itk::Image< TPixel, VImageDimension > *itkImage1)
Template class to perform the demons registration with any kind of image. Called by GenerateData()...
virtual ~DemonsRegistration()
Default destructor.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.