ITK  6.0.0
Insight Toolkit
itkMultiLabelSTAPLEImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 {
118 template <typename TInputImage, typename TOutputImage = TInputImage, typename TWeights = float>
119 class ITK_TEMPLATE_EXPORT MultiLabelSTAPLEImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
120 {
121 public:
122  ITK_DISALLOW_COPY_AND_MOVE(MultiLabelSTAPLEImageFilter);
123 
129 
131  itkNewMacro(Self);
132 
134  itkOverrideGetNameOfClassMacro(MultiLabelSTAPLEImageFilter);
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;
150 
152  using typename Superclass::OutputImageRegionType;
153 
157 
159  using WeightsType = TWeights;
162 
164  itkGetConstMacro(ElapsedNumberOfIterations, unsigned int);
165 
168  void
169  SetMaximumNumberOfIterations(const unsigned int mit)
170  {
171  this->m_MaximumNumberOfIterations = mit;
172  this->m_HasMaximumNumberOfIterations = true;
173  this->Modified();
174  }
175  itkGetConstMacro(MaximumNumberOfIterations, unsigned int);
179  itkGetConstMacro(HasMaximumNumberOfIterations, bool);
180 
183  void
185  {
186  if (this->m_HasMaximumNumberOfIterations)
187  {
188  this->m_HasMaximumNumberOfIterations = false;
189  this->Modified();
190  }
191  }
196  itkSetMacro(TerminationUpdateThreshold, TWeights);
197  itkGetConstMacro(TerminationUpdateThreshold, TWeights);
202  void
204  {
205  this->m_LabelForUndecidedPixels = l;
206  this->m_HasLabelForUndecidedPixels = true;
207  this->Modified();
208  }
218  itkGetMacro(LabelForUndecidedPixels, OutputPixelType);
219 
221  itkGetMacro(HasLabelForUndecidedPixels, bool);
222 
225  void
227  {
228  if (this->m_HasLabelForUndecidedPixels)
229  {
230  this->m_HasLabelForUndecidedPixels = false;
231  this->Modified();
232  }
233  }
242  void
244  {
245  this->m_PriorProbabilities = ppa;
246  this->m_HasPriorProbabilities = true;
247  this->Modified();
248  }
258  itkGetConstReferenceMacro(PriorProbabilities, PriorProbabilitiesType);
259 
261  itkGetMacro(HasPriorProbabilities, bool);
262 
265  void
267  {
268  if (this->m_HasPriorProbabilities)
269  {
270  this->m_HasPriorProbabilities = false;
271  this->Modified();
272  }
273  }
278  const ConfusionMatrixType &
279  GetConfusionMatrix(const unsigned int i) const
280  {
281  return this->m_ConfusionMatrixArray[i];
282  }
283 
284 protected:
286  : m_LabelForUndecidedPixels(OutputPixelType{})
287  , m_TerminationUpdateThreshold(1e-5)
288  {}
289  ~MultiLabelSTAPLEImageFilter() override = default;
290 
291  void
292  GenerateData() override;
293 
294  void
295  PrintSelf(std::ostream &, Indent) const override;
296 
298  typename TInputImage::PixelType
299  ComputeMaximumInputValue();
300 
301  // Override since the filter needs all the data for the algorithm
302  void
303  GenerateInputRequestedRegion() override;
304 
305  // Override since the filter produces all of its output
306  void
307  EnlargeOutputRequestedRegion(DataObject *) override;
308 
309 private:
310  size_t m_TotalLabelCount{ 0 };
311 
312  OutputPixelType m_LabelForUndecidedPixels{};
313  bool m_HasLabelForUndecidedPixels{ false };
314 
315  bool m_HasPriorProbabilities{ false };
316  PriorProbabilitiesType m_PriorProbabilities{};
317 
318  void
319  InitializePriorProbabilities();
320 
321  std::vector<ConfusionMatrixType> m_ConfusionMatrixArray{};
322  std::vector<ConfusionMatrixType> m_UpdatedConfusionMatrixArray{};
323 
324  void
325  AllocateConfusionMatrixArray();
326  void
327  InitializeConfusionMatrixArrayFromVoting();
328 
329  bool m_HasMaximumNumberOfIterations{ false };
330  unsigned int m_MaximumNumberOfIterations{ 0 };
331  unsigned int m_ElapsedNumberOfIterations{ 0u };
332 
333  TWeights m_TerminationUpdateThreshold{};
334 };
335 
336 } // end namespace itk
337 
338 #ifndef ITK_MANUAL_INSTANTIATION
339 # include "itkMultiLabelSTAPLEImageFilter.hxx"
340 #endif
341 
342 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::MultiLabelSTAPLEImageFilter::MultiLabelSTAPLEImageFilter
MultiLabelSTAPLEImageFilter()
Definition: itkMultiLabelSTAPLEImageFilter.h:285
itk::ImageSource::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::MultiLabelSTAPLEImageFilter::SetMaximumNumberOfIterations
void SetMaximumNumberOfIterations(const unsigned int mit)
Definition: itkMultiLabelSTAPLEImageFilter.h:169
itk::MultiLabelSTAPLEImageFilter::SetPriorProbabilities
void SetPriorProbabilities(const PriorProbabilitiesType &ppa)
Definition: itkMultiLabelSTAPLEImageFilter.h:243
itk::MultiLabelSTAPLEImageFilter::UnsetLabelForUndecidedPixels
void UnsetLabelForUndecidedPixels()
Definition: itkMultiLabelSTAPLEImageFilter.h:226
itkImage.h
itk::SmartPointer< Self >
itkImageRegionIterator.h
itk::MultiLabelSTAPLEImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkMultiLabelSTAPLEImageFilter.h:139
itk::MultiLabelSTAPLEImageFilter::GetConfusionMatrix
const ConfusionMatrixType & GetConfusionMatrix(const unsigned int i) const
Definition: itkMultiLabelSTAPLEImageFilter.h:279
itkImageRegionConstIterator.h
itk::ImageRegionIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionIterator.h:80
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::ImageToImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageToImageFilter.h:130
itk::MultiLabelSTAPLEImageFilter::UnsetPriorProbabilities
void UnsetPriorProbabilities()
Definition: itkMultiLabelSTAPLEImageFilter.h:266
itk::MultiLabelSTAPLEImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkMultiLabelSTAPLEImageFilter.h:138
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itkImageToImageFilter.h
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::MultiLabelSTAPLEImageFilter::UnsetMaximumNumberOfIterations
void UnsetMaximumNumberOfIterations()
Definition: itkMultiLabelSTAPLEImageFilter.h:184
itkArray.h
itk::MultiLabelSTAPLEImageFilter::WeightsType
TWeights WeightsType
Definition: itkMultiLabelSTAPLEImageFilter.h:159
itkArray2D.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::MultiLabelSTAPLEImageFilter::SetLabelForUndecidedPixels
void SetLabelForUndecidedPixels(const OutputPixelType l)
Definition: itkMultiLabelSTAPLEImageFilter.h:203
itk::Array< WeightsType >
itkNumericTraits.h
itk::Math::e
static constexpr double e
Definition: itkMath.h:56
itk::ImageRegionConstIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionConstIterator.h:109
itk::Array2D
Array2D class representing a 2D array.
Definition: itkArray2D.h:42
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::MultiLabelSTAPLEImageFilter
This filter performs a pixelwise combination of an arbitrary number of input images,...
Definition: itkMultiLabelSTAPLEImageFilter.h:119