ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMultiLabelSTAPLEImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkMultiLabelSTAPLEImageFilter_h
19 #define itkMultiLabelSTAPLEImageFilter_h
20 
21 #include "itkImage.h"
22 #include "itkImageToImageFilter.h"
23 
24 #include "itkImageRegionIterator.h"
26 
27 #include "vector"
28 #include "itkArray.h"
29 #include "itkArray2D.h"
30 #include "itkNumericTraits.h"
31 
32 namespace itk
33 {
117 template <typename TInputImage, typename TOutputImage = TInputImage, typename TWeights = float >
118 class ITK_TEMPLATE_EXPORT MultiLabelSTAPLEImageFilter :
119  public ImageToImageFilter< TInputImage, TOutputImage >
120 {
121 public:
122  ITK_DISALLOW_COPY_AND_ASSIGN(MultiLabelSTAPLEImageFilter);
123 
129 
131  itkNewMacro(Self);
132 
135 
138  using OutputPixelType = typename TOutputImage::PixelType;
139  using InputPixelType = typename TInputImage::PixelType;
140 
143  static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
144 
146  using InputImageType = TInputImage;
147  using OutputImageType = TOutputImage;
148  using InputImagePointer = typename InputImageType::Pointer;
149  using OutputImagePointer = typename OutputImageType::Pointer;
150 
152  using OutputImageRegionType = typename Superclass::OutputImageRegionType;
153 
157 
159  using WeightsType = TWeights;
162 
164  itkGetConstMacro(ElapsedNumberOfIterations, unsigned int);
165 
168  void SetMaximumNumberOfIterations( const unsigned int mit )
169  {
170  this->m_MaximumNumberOfIterations = mit;
171  this->m_HasMaximumNumberOfIterations = true;
172  this->Modified();
173  }
174  itkGetConstMacro(MaximumNumberOfIterations, unsigned int);
176 
178  itkGetConstMacro(HasMaximumNumberOfIterations, bool);
179 
183  {
184  if ( this->m_HasMaximumNumberOfIterations )
185  {
186  this->m_HasMaximumNumberOfIterations = false;
187  this->Modified();
188  }
189  }
191 
194  itkSetMacro(TerminationUpdateThreshold, TWeights);
195  itkGetConstMacro(TerminationUpdateThreshold, TWeights);
197 
201  {
202  this->m_LabelForUndecidedPixels = l;
203  this->m_HasLabelForUndecidedPixels = true;
204  this->Modified();
205  }
207 
215  itkGetMacro(LabelForUndecidedPixels, OutputPixelType);
216 
218  itkGetMacro(HasLabelForUndecidedPixels, bool);
219 
223  {
224  if ( this->m_HasLabelForUndecidedPixels )
225  {
226  this->m_HasLabelForUndecidedPixels = false;
227  this->Modified();
228  }
229  }
231 
239  {
240  this->m_PriorProbabilities = ppa;
241  this->m_HasPriorProbabilities = true;
242  this->Modified();
243  }
245 
253  itkGetConstReferenceMacro(PriorProbabilities, PriorProbabilitiesType);
254 
256  itkGetMacro(HasPriorProbabilities, bool);
257 
261  {
262  if ( this->m_HasPriorProbabilities )
263  {
264  this->m_HasPriorProbabilities = false;
265  this->Modified();
266  }
267  }
269 
272  const ConfusionMatrixType & GetConfusionMatrix( const unsigned int i ) const
273  {
274  return this->m_ConfusionMatrixArray[i];
275  }
276 
277 protected:
279  m_LabelForUndecidedPixels(NumericTraits<OutputPixelType>::ZeroValue()),
280  m_TerminationUpdateThreshold(1e-5)
281  {
282  }
283  ~MultiLabelSTAPLEImageFilter() override = default;
284 
285  void GenerateData() override;
286 
287  void PrintSelf(std::ostream&, Indent) const override;
288 
290  typename TInputImage::PixelType ComputeMaximumInputValue();
291 
292  // Override since the filter needs all the data for the algorithm
293  void GenerateInputRequestedRegion() override;
294 
295  // Override since the filter produces all of its output
296  void EnlargeOutputRequestedRegion( DataObject * ) override;
297 
298 private:
299  size_t m_TotalLabelCount{0};
300 
302  bool m_HasLabelForUndecidedPixels{false};
303 
304  bool m_HasPriorProbabilities{false};
306 
307  void InitializePriorProbabilities();
308 
309  std::vector<ConfusionMatrixType> m_ConfusionMatrixArray;
310  std::vector<ConfusionMatrixType> m_UpdatedConfusionMatrixArray;
311 
312  void AllocateConfusionMatrixArray();
313  void InitializeConfusionMatrixArrayFromVoting();
314 
315  bool m_HasMaximumNumberOfIterations{false};
316  unsigned int m_MaximumNumberOfIterations{0};
317  unsigned int m_ElapsedNumberOfIterations{0u};
318 
320 };
321 
322 } // end namespace itk
323 
324 #ifndef ITK_MANUAL_INSTANTIATION
325 #include "itkMultiLabelSTAPLEImageFilter.hxx"
326 #endif
327 
328 #endif
std::vector< ConfusionMatrixType > m_ConfusionMatrixArray
typename OutputImageType::Pointer OutputImagePointer
Define numeric traits for std::vector.
typename TOutputImage::PixelType OutputPixelType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
void SetLabelForUndecidedPixels(const OutputPixelType l)
typename InputImageType::Pointer InputImagePointer
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
typename OutputImageType::RegionType OutputImageRegionType
A multi-dimensional iterator templated over image type that walks a region of pixels.
TOutputImage OutputImageType
const ConfusionMatrixType & GetConfusionMatrix(const unsigned int i) const
void SetMaximumNumberOfIterations(const unsigned int mit)
This filter performs a pixelwise combination of an arbitrary number of input images, where each of them represents a segmentation of the same scene (i.e., image).
std::vector< ConfusionMatrixType > m_UpdatedConfusionMatrixArray
static constexpr double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:53
Base class for filters that take an image as input and produce an image as output.
void SetPriorProbabilities(const PriorProbabilitiesType &ppa)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename TInputImage::PixelType InputPixelType
Base class for all data objects in ITK.
A multi-dimensional iterator templated over image type that walks a region of pixels.