Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDWIHeadMotionCorrectionFilter.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKDWIHEADMOTIONCORRECTIONFILTER_H
18 #define MITKDWIHEADMOTIONCORRECTIONFILTER_H
19 
20 #include "mitkImageToImageFilter.h"
21 
22 #include <itkAccumulateImageFilter.h>
23 #include <itkExtractImageFilter.h>
24 
25 #include "mitkITKImageImport.h"
26 #include <itkVectorImage.h>
28 
29 namespace mitk
30 {
31 
46  : public ImageToImageFilter
47 {
48 public:
49 
50  // class macros
53 
54  itkFactorylessNewMacro(Self)
55  itkCloneMacro(Self)
56 
57  itkGetMacro( Steps, unsigned long )
58  itkGetMacro( CurrentStep, unsigned long )
59  itkGetMacro( IsInValidState, bool)
60  itkSetMacro( AbortRegistration, bool )
61  itkSetMacro( AverageUnweighted, bool )
62 
63  // public typedefs
64  typedef short DiffusionPixelType;
67  typedef itk::VectorImage<DiffusionPixelType, 3> ITKDiffusionImageType;
68 
69 protected:
71  virtual ~DWIHeadMotionCorrectionFilter() {}
72 
73  virtual void GenerateData() override;
74 
75  unsigned long m_CurrentStep;
76  unsigned long m_Steps;
80 
81 };
82 
89 template< typename TPixel, unsigned int VDimensions>
90 static void ItkAccumulateFilter(
91  const itk::Image< TPixel, VDimensions>* image,
92  mitk::Image::Pointer& output)
93 {
94  // input 3d+t --> output 3d
95  typedef itk::Image< TPixel, 4> InputItkType;
96  typedef itk::Image< TPixel, 3> OutputItkType;
97  // the accumulate filter requires the same dimension in output and input image
98  typedef typename itk::AccumulateImageFilter< InputItkType, InputItkType > FilterType;
99 
100  typename FilterType::Pointer filter = FilterType::New();
101  filter->SetInput( image );
102  filter->SetAccumulateDimension( 3 );
103  filter->SetAverage( true );
104 
105  // we need to extract the volume to reduce the size from 4 to 3 for further processing
106  typedef typename itk::ExtractImageFilter< InputItkType, OutputItkType > ExtractFilterType;
107  typename ExtractFilterType::Pointer extractor = ExtractFilterType::New();
108  extractor->SetInput( filter->GetOutput() );
109  extractor->SetDirectionCollapseToIdentity();
110 
111  typename InputItkType::RegionType extractRegion = image->GetLargestPossibleRegion();
112  // crop out the time axis
113  extractRegion.SetSize( 3, 0);
114  extractor->SetExtractionRegion( extractRegion );
115 
116  try
117  {
118  extractor->Update();
119  }
120  catch( const itk::ExceptionObject& e)
121  {
122  mitkThrow() << " Exception while averaging: " << e.what();
123  }
124 
125  output = mitk::GrabItkImageMemory( extractor->GetOutput() );
126 }
127 
128 } //end namespace mitk
129 
130 
131 #endif // MITKDWIHEADMOTIONCORRECTIONFILTER_H
itk::SmartPointer< Self > Pointer
Superclass of all classes generating some kind of mitk::BaseData.
DataCollection - Class to facilitate loading/accessing structured data.
#define MITKDIFFUSIONCORE_EXPORT
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.
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
#define mitkThrow()
Image class for storing images.
Definition: mitkImage.h:76
Superclass of all classes having one or more Images as input and generating Images as output...
Performs standard head-motion correction by using affine registration of the gradient images...
bool m_IsInValidState
Whether the filter is in a valid state, false if error occured.
itk::VectorImage< DiffusionPixelType, 3 > ITKDiffusionImageType
itk::ProcessObject Superclass
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.