Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkMaskedDynamicImageStatisticsGenerator.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include "mitkImageTimeSelector.h"
16 #include "mitkImageAccessByItk.h"
17 #include "mitkImageCast.h"
19 
21 {
22  m_Mask = nullptr;
23  m_DynamicImage = nullptr;
24 };
25 
27 
29 {
30  if(this->HasOutdatedResults())
31  {
33  Generate();
34  }
35  return m_Maximum;
36 };
37 
39 {
40  if(this->HasOutdatedResults())
41  {
43  Generate();
44  }
45  return m_Minimum;
46 };
47 
49 {
50  if(this->HasOutdatedResults())
51  {
53  Generate();
54  }
55  return m_Mean;
56 };
57 
59 {
60  if(this->HasOutdatedResults())
61  {
63  Generate();
64  }
65  return m_Sigma;
66 };
67 
69 {
70  if(this->HasOutdatedResults())
71  {
73  Generate();
74  }
75  return m_Variance;
76 };
77 
79 {
80  if(this->HasOutdatedResults())
81  {
83  Generate();
84  }
85  return m_Sum;
86 };
87 
88 template <typename TPixel, unsigned int VDim>
89 void mitk::MaskedDynamicImageStatisticsGenerator::DoCalculateStatistics(const itk::Image<TPixel, VDim>* /*image*/)
90 {
91  typedef itk::Image<TPixel, VDim-1> InputFrameImageType;
93 
94  typename FilterType::Pointer statFilter = FilterType::New();
95 
96  //add the time frames to the fit filter
97  unsigned int timeSteps = this->m_DynamicImage->GetTimeSteps();
98  std::vector<Image::Pointer> frameCache;
100  imageTimeSelector->SetInput(this->m_DynamicImage);
101  for (unsigned int i = 0; i < timeSteps; ++i)
102  {
103  typename InputFrameImageType::Pointer frameImage;
104  imageTimeSelector->SetTimeNr(i);
105  imageTimeSelector->UpdateLargestPossibleRegion();
106 
107  Image::Pointer frameMITKImage = imageTimeSelector->GetOutput();
108  frameCache.push_back(frameMITKImage);
109  mitk::CastToItkImage(frameMITKImage, frameImage);
110  statFilter->SetInput(i,frameImage);
111  }
112 
113  if (this->m_InternalMask.IsNotNull())
114  {
115  statFilter->SetMask(this->m_InternalMask);
116  }
117 
118  statFilter->Update();
119 
120  m_Maximum.SetSize(timeSteps);
121  m_Minimum.SetSize(timeSteps);
122  m_Mean.SetSize(timeSteps);
123  m_Sigma.SetSize(timeSteps);
124  m_Variance.SetSize(timeSteps);
125  m_Sum.SetSize(timeSteps);
126 
127  for (unsigned int i = 0; i < timeSteps; ++i)
128  {
129  m_Maximum.SetElement(i,statFilter->GetMaximum()[i]);
130  m_Minimum.SetElement(i,statFilter->GetMinimum()[i]);
131  m_Mean.SetElement(i,statFilter->GetMean()[i]);
132  m_Sigma.SetElement(i,statFilter->GetSigma()[i]);
133  m_Variance.SetElement(i,statFilter->GetVariance()[i]);
134  m_Sum.SetElement(i,statFilter->GetSum()[i]);
135  }
136 
137  this->m_GenerationTimeStamp.Modified();
138 }
139 
141 {
142  if(this->m_Mask.IsNotNull())
143  {
144  InternalMaskType::Pointer castedMask;
145  CastToItkImage<InternalMaskType>(m_Mask, castedMask);
146  if (castedMask.IsNull())
147  {
148  mitkThrow() << "Dynamic cast of mask went wrong. Internal Mask is NULL. Image statistics cannot be generated.";
149  }
150 
151  this->m_InternalMask = castedMask;
152  }
153  else
154  {
155  this->m_InternalMask = nullptr;
156  }
157 
159 }
160 
161 void
163 {
164 
165  if (m_DynamicImage.IsNull())
166  {
167  mitkThrow() << "Cannot generate statistics. Input dynamic image is not set.";
168  }
169 }
170 
171 bool
173 {
174  bool result = this->GetMTime() > this->m_GenerationTimeStamp;
175 
176  if (m_DynamicImage.IsNotNull())
177  {
178  if (m_DynamicImage->GetMTime() > this->m_GenerationTimeStamp)
179  {
180  result = true;
181  }
182  }
183 
184  if (m_Mask.IsNotNull())
185  {
186  if (m_Mask->GetMTime() > this->m_GenerationTimeStamp)
187  {
188  result = true;
189  }
190  }
191  return result;
192 
193 };
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
class ITK_EXPORT Image
#define mitkThrow()
Computes a masked statistic on N images and produces vectors of those statistic results.
void DoCalculateStatistics(const itk::Image< TPixel, VDim > *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.
static Pointer New()