7 #include <itkResampleImageFilter.h>
8 #include <itkWindowedSincInterpolateImageFunction.h>
9 #include <itkLinearInterpolateImageFunction.h>
10 #include <itkNearestNeighborExtrapolateImageFunction.h>
11 #include <itkBSplineInterpolateImageFunction.h>
15 #include <itkImageDuplicator.h>
17 #include <vnl/vnl_inverse.h>
29 typedef itk::Euler3DTransform< double > RigidTransformType;
31 RigidTransformType::ParametersType parameters(RigidTransformType::ParametersDimension);
33 for (
int i = 0; i<6;++i)
34 parameters[i] = transformation[i];
36 rtransform->SetParameters( parameters );
40 if (offset[0] != 0 || offset[1] != 0 || offset[2] != 0)
47 mitk::Point3D newOrigin = rtransform->GetInverseTransform()->TransformPoint(origin);
49 itk::Matrix<double,3,3> dir = itkImage->GetDirection();
50 itk::Matrix<double,3,3> transM ( vnl_inverse(rtransform->GetMatrix().GetVnlMatrix()));
51 itk::Matrix<double,3,3> newDirection = transM * dir;
53 itkImage->SetOrigin(newOrigin);
54 itkImage->SetDirection(newDirection);
57 if (resampleReference != NULL)
59 typedef itk::ResampleImageFilter<ItkImageType, ItkImageType> ResampleFilterType;
64 typedef itk::Function::WelchWindowFunction<4> WelchWindowFunction;
65 typedef itk::WindowedSincInterpolateImageFunction< ItkImageType, 4,WelchWindowFunction> WindowedSincInterpolatorType;
69 typedef itk::LinearInterpolateImageFunction< ItkImageType> LinearInterpolatorType;
72 typedef itk::NearestNeighborInterpolateImageFunction< ItkImageType, double > NearestNeighborInterpolatorType;
75 typedef itk::BSplineInterpolateImageFunction< ItkImageType, double > BSplineInterpolatorType;
80 resampler->SetInput(itkImage);
81 resampler->SetReferenceImage( itkReference );
82 resampler->UseReferenceImageOn();
84 resampler->SetInterpolator(nn_interpolator);
86 resampler->SetInterpolator(lin_interpolator);
100 duplicator->SetInputImage(itkImage);
101 duplicator->Update();
112 typedef itk::Euler3DTransform< double > RigidTransformType;
114 RigidTransformType::ParametersType parameters(RigidTransformType::ParametersDimension);
116 for (
int i = 0; i<6;++i)
118 parameters[i] = transformation[i];
121 rtransform->SetParameters( parameters );
123 typedef itk::VectorImage<short, 3> ITKDiffusionImageType;
129 if (offset[0] != 0 || offset[1] != 0 || offset[2] != 0)
131 b0origin[0]=offset[0];
132 b0origin[1]=offset[1];
133 b0origin[2]=offset[2];
136 mitk::Point3D newOrigin = rtransform->GetInverseTransform()->TransformPoint(b0origin);
138 itk::Matrix<double,3,3> dir = itkVectorImagePointer->GetDirection();
139 itk::Matrix<double,3,3> transM ( vnl_inverse(rtransform->GetMatrix().GetVnlMatrix()));
140 itk::Matrix<double,3,3> newDirection = transM * dir;
142 itkVectorImagePointer->SetOrigin(newOrigin);
143 itkVectorImagePointer->SetDirection(newDirection);
151 duplicator->SetInputImage(itkVectorImagePointer);
152 duplicator->Update();
164 correctionFilter->SetImage(img);
165 correctionFilter->CorrectDirections(transM.GetVnlMatrix());
175 offset[0]=offset[1]=offset[2]=0;
177 typedef itk::VectorImage<short, 3> ITKDiffusionImageType;
188 b0Extraction->SetInput( itkFixedDwiPointer );
189 b0Extraction->SetDirections(fixedGradientDirections);
190 b0Extraction->Update();
192 tmp->InitializeByItk(b0Extraction->GetOutput());
193 tmp->SetVolume(b0Extraction->GetOutput()->GetBufferPointer());
204 b0Extraction->SetInput( itkMovingDwiPointer );
205 b0Extraction->SetDirections(movingGradientDirections);
206 b0Extraction->Update();
208 tmp->InitializeByItk(b0Extraction->GetOutput());
209 tmp->SetVolume(b0Extraction->GetOutput()->GetBufferPointer());
217 Point3D center = fixedImage->GetGeometry()->GetCenter();
218 Point3D centerMoving = movingImage->GetGeometry()->GetCenter();
219 Point3D originMoving = movingImage->GetGeometry()->GetOrigin();
226 offset[0] = (originMoving[0]-centerMoving[0])+center[0];
227 offset[1] = (originMoving[1]-centerMoving[1])+center[1];
228 offset[2] = (originMoving[2]-centerMoving[2])+center[2];
230 translatedOrigin[0]= offset[0];
231 translatedOrigin[1]= offset[1];
232 translatedOrigin[2]= offset[2];
233 tmpImage->GetGeometry()->SetOrigin(translatedOrigin);
237 registrationMethod->SetFixedImage( fixedImage );
241 registrationMethod->SetFixedImageMask(mask);
242 registrationMethod->SetUseFixedImageMask(
true);
246 registrationMethod->SetUseFixedImageMask(
false);
249 registrationMethod->SetTransformToRigid();
250 registrationMethod->SetCrossModalityOn();
251 registrationMethod->SetVerboseOn();
254 registrationMethod->SetMovingImage(tmpImage);
255 registrationMethod->Update();
256 registrationMethod->GetParameters(transformation);
bool IsDiffusionWeightedImage() const
static const std::string REFERENCEBVALUEPROPERTYNAME
itk::SmartPointer< Self > Pointer
double * RidgidTransformType
static Pointer New()
Method for creation through the object factory.
Helper class for mitk::Images containing diffusion weighted data.
static void GetTransformation(Image::Pointer fixedImage, Image::Pointer movingImage, RidgidTransformType transformation, double *offset, bool useSameOrigin=true, mitk::Image *mask=NULL)
GetTransformation Registeres the moving to the fixed image and returns the according transformation...
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
static const std::string MEASUREMENTFRAMEPROPERTYNAME
void InitializeImage()
Make certain the owned image is up to date with all necessary properties.
static void ApplyTransformationToImage(mitk::Image::Pointer img, const RidgidTransformType &transformation, double *offset, mitk::Image *resampleReference=NULL, bool binary=false)
ApplyTransformationToImage Applies transformation from GetTransformation to provided image...
Image class for storing images.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
static const std::string GRADIENTCONTAINERPROPERTYNAME
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.