ITK  4.4.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 
31 namespace itk
32 {
116 template <typename TInputImage, typename TOutputImage = TInputImage, typename TWeights = float >
117 class ITK_EXPORT MultiLabelSTAPLEImageFilter :
118  public ImageToImageFilter< TInputImage, TOutputImage >
119 {
120 public:
126 
128  itkNewMacro(Self);
129 
132 
135  typedef typename TOutputImage::PixelType OutputPixelType;
136  typedef typename TInputImage::PixelType InputPixelType;
137 
140  itkStaticConstMacro(ImageDimension, unsigned int,
141  TOutputImage::ImageDimension);
142 
144  typedef TInputImage InputImageType;
145  typedef TOutputImage OutputImageType;
146  typedef typename InputImageType::Pointer InputImagePointer;
147  typedef typename OutputImageType::Pointer OutputImagePointer;
148 
150  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
151 
155 
157  typedef TWeights WeightsType;
160 
163  void SetMaximumNumberOfIterations( const unsigned int mit )
164  {
165  this->m_MaximumNumberOfIterations = mit;
166  this->m_HasMaximumNumberOfIterations = true;
167  this->Modified();
168  }
170 
173  void UnsetMaximumNumberOfIterations()
174  {
175  if ( this->m_HasMaximumNumberOfIterations )
176  {
177  this->m_HasMaximumNumberOfIterations = false;
178  this->Modified();
179  }
180  }
182 
185  void SetTerminationUpdateThreshold( const TWeights thresh )
186  {
187  this->m_TerminationUpdateThreshold = thresh;
188  this->Modified();
189  }
191 
194  void SetLabelForUndecidedPixels( const OutputPixelType l )
195  {
196  this->m_LabelForUndecidedPixels = l;
197  this->m_HasLabelForUndecidedPixels = true;
198  this->Modified();
199  }
201 
208  OutputPixelType GetLabelForUndecidedPixels() const
209  {
210  return this->m_LabelForUndecidedPixels;
211  }
212 
215  void UnsetLabelForUndecidedPixels()
216  {
217  if ( this->m_HasLabelForUndecidedPixels )
218  {
219  this->m_HasLabelForUndecidedPixels = false;
220  this->Modified();
221  }
222  }
224 
227  void SetPriorProbabilities( const PriorProbabilitiesType& ppa )
228  {
229  this->m_PriorProbabilities = ppa;
230  this->m_HasPriorProbabilities = true;
231  this->Modified();
232  }
234 
241  PriorProbabilitiesType GetPriorProbabilities() const
242  {
243  return this->m_PriorProbabilities;
244  }
245 
248  void UnsetPriorProbabilities()
249  {
250  if ( this->m_HasPriorProbabilities )
251  {
252  this->m_HasPriorProbabilities = false;
253  this->Modified();
254  }
255  }
257 
260  ConfusionMatrixType GetConfusionMatrix( const unsigned int i )
261  {
262  return this->m_ConfusionMatrixArray[i];
263  }
264 
265 protected:
267  {
268  this->m_HasLabelForUndecidedPixels = false;
269  this->m_HasPriorProbabilities = false;
270  this->m_HasMaximumNumberOfIterations = false;
271  this->m_TerminationUpdateThreshold = 1e-5;
272  }
274 
275  void GenerateData();
276 
277  void PrintSelf(std::ostream&, Indent) const;
278 
280  typename TInputImage::PixelType ComputeMaximumInputValue();
281 
282  // Override since the filter needs all the data for the algorithm
283  void GenerateInputRequestedRegion();
284 
285  // Override since the filter produces all of its output
286  void EnlargeOutputRequestedRegion( DataObject * );
287 
288 private:
289  MultiLabelSTAPLEImageFilter(const Self&); //purposely not implemented
290  void operator=(const Self&); //purposely not implemented
291 
293 
296 
299 
300  void InitializePriorProbabilities();
301 
302  std::vector<ConfusionMatrixType> m_ConfusionMatrixArray;
303  std::vector<ConfusionMatrixType> m_UpdatedConfusionMatrixArray;
304 
305  void AllocateConfusionMatrixArray();
306  void InitializeConfusionMatrixArrayFromVoting();
307 
310 
312 };
313 
314 } // end namespace itk
315 
316 #ifndef ITK_MANUAL_INSTANTIATION
317 #include "itkMultiLabelSTAPLEImageFilter.hxx"
318 #endif
319 
320 #endif
321