ITK  4.13.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:
127 
129  itkNewMacro(Self);
130 
133 
136  typedef typename TOutputImage::PixelType OutputPixelType;
137  typedef typename TInputImage::PixelType InputPixelType;
138 
141  itkStaticConstMacro(ImageDimension, unsigned int,
142  TOutputImage::ImageDimension);
143 
145  typedef TInputImage InputImageType;
146  typedef TOutputImage OutputImageType;
147  typedef typename InputImageType::Pointer InputImagePointer;
148  typedef typename OutputImageType::Pointer OutputImagePointer;
149 
151  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
152 
156 
158  typedef TWeights WeightsType;
161 
163  itkGetConstMacro(ElapsedNumberOfIterations, unsigned int);
164 
167  void SetMaximumNumberOfIterations( const unsigned int mit )
168  {
169  this->m_MaximumNumberOfIterations = mit;
170  this->m_HasMaximumNumberOfIterations = true;
171  this->Modified();
172  }
173  itkGetConstMacro(MaximumNumberOfIterations, unsigned int);
175 
177  itkGetConstMacro(HasMaximumNumberOfIterations, bool);
178 
182  {
183  if ( this->m_HasMaximumNumberOfIterations )
184  {
185  this->m_HasMaximumNumberOfIterations = false;
186  this->Modified();
187  }
188  }
190 
193  itkSetMacro(TerminationUpdateThreshold, TWeights);
194  itkGetConstMacro(TerminationUpdateThreshold, TWeights);
196 
200  {
201  this->m_LabelForUndecidedPixels = l;
202  this->m_HasLabelForUndecidedPixels = true;
203  this->Modified();
204  }
206 
214  itkGetMacro(LabelForUndecidedPixels, OutputPixelType);
215 
217  itkGetMacro(HasLabelForUndecidedPixels, bool);
218 
222  {
223  if ( this->m_HasLabelForUndecidedPixels )
224  {
225  this->m_HasLabelForUndecidedPixels = false;
226  this->Modified();
227  }
228  }
230 
238  {
239  this->m_PriorProbabilities = ppa;
240  this->m_HasPriorProbabilities = true;
241  this->Modified();
242  }
244 
252  itkGetConstReferenceMacro(PriorProbabilities, PriorProbabilitiesType);
253 
255  itkGetMacro(HasPriorProbabilities, bool);
256 
260  {
261  if ( this->m_HasPriorProbabilities )
262  {
263  this->m_HasPriorProbabilities = false;
264  this->Modified();
265  }
266  }
268 
271  const ConfusionMatrixType & GetConfusionMatrix( const unsigned int i ) const
272  {
273  return this->m_ConfusionMatrixArray[i];
274  }
275 
276 protected:
278  m_TotalLabelCount(0),
279  m_LabelForUndecidedPixels(NumericTraits<OutputPixelType>::ZeroValue()),
280  m_HasLabelForUndecidedPixels(false),
281  m_HasPriorProbabilities(false),
282  m_HasMaximumNumberOfIterations(false),
283  m_MaximumNumberOfIterations(0),
284  m_ElapsedNumberOfIterations(0u),
285  m_TerminationUpdateThreshold(1e-5)
286  {
287  }
288  virtual ~MultiLabelSTAPLEImageFilter() ITK_OVERRIDE {}
289 
290  void GenerateData() ITK_OVERRIDE;
291 
292  void PrintSelf(std::ostream&, Indent) const ITK_OVERRIDE;
293 
295  typename TInputImage::PixelType ComputeMaximumInputValue();
296 
297  // Override since the filter needs all the data for the algorithm
298  void GenerateInputRequestedRegion() ITK_OVERRIDE;
299 
300  // Override since the filter produces all of its output
301  void EnlargeOutputRequestedRegion( DataObject * ) ITK_OVERRIDE;
302 
303 private:
304  ITK_DISALLOW_COPY_AND_ASSIGN(MultiLabelSTAPLEImageFilter);
305 
306  size_t m_TotalLabelCount;
307 
308  OutputPixelType m_LabelForUndecidedPixels;
309  bool m_HasLabelForUndecidedPixels;
310 
311  bool m_HasPriorProbabilities;
312  PriorProbabilitiesType m_PriorProbabilities;
313 
314  void InitializePriorProbabilities();
315 
316  std::vector<ConfusionMatrixType> m_ConfusionMatrixArray;
317  std::vector<ConfusionMatrixType> m_UpdatedConfusionMatrixArray;
318 
319  void AllocateConfusionMatrixArray();
320  void InitializeConfusionMatrixArrayFromVoting();
321 
322  bool m_HasMaximumNumberOfIterations;
323  unsigned int m_MaximumNumberOfIterations;
324  unsigned int m_ElapsedNumberOfIterations;
325 
326  TWeights m_TerminationUpdateThreshold;
327 };
328 
329 } // end namespace itk
330 
331 #ifndef ITK_MANUAL_INSTANTIATION
332 #include "itkMultiLabelSTAPLEImageFilter.hxx"
333 #endif
334 
335 #endif
ImageToImageFilter< TInputImage, TOutputImage > Superclass
Base class for all process objects that output image data.
void SetLabelForUndecidedPixels(const OutputPixelType l)
ImageRegionIterator< TOutputImage > OutputIteratorType
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
A multi-dimensional iterator templated over image type that walks a region of pixels.
const ConfusionMatrixType & GetConfusionMatrix(const unsigned int i) const
Superclass::OutputImageRegionType OutputImageRegionType
ImageRegionConstIterator< TInputImage > InputConstIteratorType
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).
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
Define additional traits for native types such as int or float.
static ITK_CONSTEXPR_VAR double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:56
Base class for all data objects in ITK.
A multi-dimensional iterator templated over image type that walks a region of pixels.