Orfeo Toolbox  3.16
itkVotingBinaryImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkVotingBinaryImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-17 20:50:03 $
7  Version: $Revision: 1.11 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkVotingBinaryImageFilter_txx
18 #define __itkVotingBinaryImageFilter_txx
20 
23 #include "itkImageRegionIterator.h"
26 #include "itkOffset.h"
27 #include "itkProgressReporter.h"
28 
29 #include <vector>
30 #include <algorithm>
31 
32 namespace itk
33 {
34 
35 template <class TInputImage, class TOutputImage>
38 {
39  m_Radius.Fill(1);
40  m_ForegroundValue = NumericTraits<InputPixelType>::max();
41  m_BackgroundValue = NumericTraits<InputPixelType>::Zero;
42  m_BirthThreshold = 1;
43  m_SurvivalThreshold = 1;
44 }
45 
46 template <class TInputImage, class TOutputImage>
47 void
50 {
51  // call the superclass' implementation of this method
52  Superclass::GenerateInputRequestedRegion();
53 
54  // get pointers to the input and output
55  typename Superclass::InputImagePointer inputPtr =
56  const_cast< TInputImage * >( this->GetInput() );
57  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
58 
59  if ( !inputPtr || !outputPtr )
60  {
61  return;
62  }
63 
64  // get a copy of the input requested region (should equal the output
65  // requested region)
66  typename TInputImage::RegionType inputRequestedRegion;
67  inputRequestedRegion = inputPtr->GetRequestedRegion();
68 
69  // pad the input requested region by the operator radius
70  inputRequestedRegion.PadByRadius( m_Radius );
71 
72  // crop the input requested region at the input's largest possible region
73  if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
74  {
75  inputPtr->SetRequestedRegion( inputRequestedRegion );
76  return;
77  }
78  else
79  {
80  // Couldn't crop the region (requested region is outside the largest
81  // possible region). Throw an exception.
82 
83  // store what we tried to request (prior to trying to crop)
84  inputPtr->SetRequestedRegion( inputRequestedRegion );
85 
86  // build an exception
87  InvalidRequestedRegionError e(__FILE__, __LINE__);
88  e.SetLocation(ITK_LOCATION);
89  e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
90  e.SetDataObject(inputPtr);
91  throw e;
92  }
93 }
94 
95 
96 template< class TInputImage, class TOutputImage>
97 void
99 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
100  int threadId)
101 {
102 
104 
107 
108  // Allocate output
109  typename OutputImageType::Pointer output = this->GetOutput();
110  typename InputImageType::ConstPointer input = this->GetInput();
111 
112  // Find the data-set boundary "faces"
115  faceList = bC(input, outputRegionForThread, m_Radius);
116 
118 
119  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
120 
121  // Process each of the boundary faces. These are N-d regions which border
122  // the edge of the buffer.
123  for (fit = faceList.begin(); fit != faceList.end(); ++fit)
124  {
125  bit = ConstNeighborhoodIterator<InputImageType>(m_Radius, input, *fit);
126  it = ImageRegionIterator<OutputImageType>(output, *fit);
127  bit.OverrideBoundaryCondition(&nbc);
128  bit.GoToBegin();
129 
130  unsigned int neighborhoodSize = bit.Size();
131 
132  while ( ! bit.IsAtEnd() )
133  {
134  const InputPixelType inpixel = bit.GetCenterPixel();
135 
136  // count the pixels ON in the neighborhood
137  unsigned int count = 0;
138  for (unsigned int i = 0; i < neighborhoodSize; ++i)
139  {
140  InputPixelType value = bit.GetPixel(i);
141  if( value == m_ForegroundValue )
142  {
143  count++;
144  }
145  }
146 
147  if( inpixel == m_BackgroundValue )
148  {
149  if( count >= m_BirthThreshold )
150  {
151  it.Set( static_cast<OutputPixelType>( m_ForegroundValue ) );
152  }
153  else
154  {
155  it.Set( static_cast<OutputPixelType>( m_BackgroundValue ) );
156  }
157  }
158  else
159  {
160  if( inpixel == m_ForegroundValue )
161  {
162  if( count >= m_SurvivalThreshold )
163  {
164  it.Set( static_cast<OutputPixelType>( m_ForegroundValue ) );
165  }
166  else
167  {
168  it.Set( static_cast<OutputPixelType>( m_BackgroundValue ) );
169  }
170  }
171  }
172  ++bit;
173  ++it;
174  progress.CompletedPixel();
175  }
176  }
177 }
178 
182 template <class TInputImage, class TOutput>
183 void
186  std::ostream& os,
187  Indent indent) const
188 {
189  Superclass::PrintSelf( os, indent );
190  os << indent << "Radius: " << m_Radius << std::endl;
191  os << indent << "Foreground value : "
192  << static_cast<typename NumericTraits<InputPixelType>::PrintType>( m_ForegroundValue )<< std::endl;
193  os << indent << "Background value : "
194  << static_cast<typename NumericTraits<InputPixelType>::PrintType>( m_BackgroundValue ) << std::endl;
195  os << indent << "Birth Threshold : " << m_BirthThreshold << std::endl;
196  os << indent << "Survival Threshold : " << m_SurvivalThreshold << std::endl;
197 
198 }
199 
200 } // end namespace itk
201 
202 #endif

Generated at Sun Feb 3 2013 00:14:08 for Orfeo Toolbox with doxygen 1.8.1.1