18 #ifndef MITKDWIHEADMOTIONCORRECTIONFILTER_CPP
19 #define MITKDWIHEADMOTIONCORRECTIONFILTER_CPP
44 m_IsInValidState(true),
45 m_AbortRegistration(false),
46 m_AverageUnweighted(true)
63 unsigned int numberOfSteps = itkVectorImagePointer->GetNumberOfComponentsPerPixel () ;
64 m_Steps = numberOfSteps;
72 b0_extractor->SetInput( itkVectorImagePointer );
74 b0_extractor->Update();
77 b0Image->InitializeByItk( b0_extractor->GetOutput() );
78 b0Image->SetImportChannel( b0_extractor->GetOutput()->GetBufferPointer(),
85 t_selector->SetInput( b0Image );
86 t_selector->SetTimeNr(0);
91 const unsigned int numberOfb0Images = b0Image->GetTimeSteps();
94 if( m_AverageUnweighted && numberOfb0Images > 1)
98 registrationMethod->SetFixedImage( b0referenceImage );
99 registrationMethod->SetTransformToRigid();
102 registrationMethod->SetCrossModalityOff();
105 registrationMethod->SetUseAdvancedInterpolation(
true);
113 t_selector2->SetInput( b0Image );
115 for(
unsigned int i=1; i<numberOfb0Images; i++)
118 m_CurrentStep = i + 1;
119 if( m_AbortRegistration ==
true) {
120 m_IsInValidState =
false;
124 t_selector2->SetTimeNr(i);
125 t_selector2->Update();
127 registrationMethod->SetMovingImage( t_selector2->GetOutput() );
131 MITK_INFO <<
" === (" << i <<
"/"<< numberOfb0Images-1 <<
") :: Starting registration";
132 registrationMethod->Update();
134 catch(
const itk::ExceptionObject& e)
136 m_IsInValidState =
false;
137 mitkThrow() <<
"Failed to register the b0 images, the PyramidRegistration threw an exception: \n" << e.what();
142 registeredB0Image->SetImportVolume( imac.GetData(),
156 split_filter->SetInput (itkVectorImagePointer );
161 split_filter->Update();
163 catch(
const itk::ExceptionObject &e)
165 m_IsInValidState =
false;
166 mitkThrow() <<
" Caught exception from SplitImageFilter : " << e.what();
170 splittedImage->InitializeByItk( split_filter->GetOutput() );
171 splittedImage->SetImportChannel( split_filter->GetOutput()->GetBufferPointer(),
183 weightedRegistrationMethod->SetTransformToAffine();
184 weightedRegistrationMethod->SetCrossModalityOn();
191 weightedRegistrationMethod->SetFixedImage( b0referenceImage );
193 weightedRegistrationMethod->SetUseAdvancedInterpolation(
true);
194 weightedRegistrationMethod->SetVerboseOn();
199 unsigned int maxImageIdx = splittedImage->GetTimeSteps();
202 ptg->
Expand(maxImageIdx+1);
207 registeredWeighted->Initialize( splittedImage->GetPixelType(0), *tsg );
213 registeredWeighted->SetImportVolume( imac.
GetData(),
224 t_selector_w->SetInput( splittedImage );
227 typedef RegistrationMethod::TransformMatrixType MatrixType;
228 std::vector< MatrixType > estimated_transforms;
231 for(
unsigned int i=0; i<maxImageIdx; i++)
233 m_CurrentStep = numberOfb0Images + i + 1;
234 if( m_AbortRegistration ==
true) {
235 m_IsInValidState =
false;
239 t_selector_w->SetTimeNr(i);
240 t_selector_w->Update();
242 weightedRegistrationMethod->SetMovingImage( t_selector_w->GetOutput() );
246 MITK_INFO <<
" === (" << i+1 <<
"/"<< maxImageIdx <<
") :: Starting registration";
247 weightedRegistrationMethod->Update();
249 catch(
const itk::ExceptionObject& e)
251 m_IsInValidState =
false;
252 mitkThrow() <<
"Failed to register the b0 images, the PyramidRegistration threw an exception: \n" << e.what();
257 registeredWeighted->SetImportVolume( imac.GetData(),
260 estimated_transforms.push_back( weightedRegistrationMethod->GetLastRotationMatrix() );
271 bzero_vector.fill(0);
276 gradients_new->push_back( bzero_vector );
278 SplitFilterType::IndexListType index_list = split_filter->GetIndexList();
279 SplitFilterType::IndexListType::const_iterator lIter = index_list.begin();
281 while( lIter != index_list.end() )
283 gradients_new->push_back( gradients->at( *lIter ) );
297 corrector->SetImage( output );
298 corrector->CorrectDirections( estimated_transforms );
305 this->GetOutput()->Initialize( output );
313 this->GetOutput()->Modified();
316 #endif // MITKDWIHEADMOTIONCORRECTIONFILTER_CPP
static const std::string REFERENCEBVALUEPROPERTYNAME
itk::SmartPointer< Self > Pointer
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const override
Returns the geometry which corresponds to the given time step.
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
Helper class for mitk::Images containing diffusion weighted data.
The PyramidImageRegistration class implements a multi-scale registration method.
DWIHeadMotionCorrectionFilter()
void * GetData()
Gives full data access.
static const std::string MEASUREMENTFRAMEPROPERTYNAME
GradientDirectionsProperty::GradientDirectionsContainerType GradientDirectionsContainerType
void InitializeImage()
Make certain the owned image is up to date with all necessary properties.
virtual void Expand(TimeStepType size) override
Expands the time geometry to the given number of time steps.
virtual void SetTimeStepGeometry(BaseGeometry *geometry, TimeStepType timeStep) override
Sets the geometry for the given time step.
Splits a DW-Image passed in as input into a 3D-t image where each volume coresponds to a gradient ima...
Image class for storing images.
GradientDirectionsProperty::GradientDirectionType GradientDirectionType
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
ImageWriteAccessor class to get locked write-access for a particular image part.
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 const std::string BVALUEMAPPROPERTYNAME
static void ItkAccumulateFilter(const itk::Image< TPixel, VDimensions > *image, mitk::Image::Pointer &output)
Averages an 3d+t image along the time axis.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.