Orfeo Toolbox  3.16
itkConnectedThresholdImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkConnectedThresholdImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-04-21 12:29:36 $
7  Version: $Revision: 1.30 $
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 __itkConnectedThresholdImageFilter_txx
18 #define __itkConnectedThresholdImageFilter_txx
19 
23 #include "itkProgressReporter.h"
24 
25 #ifdef ITK_USE_REVIEW
27 #endif
28 
29 namespace itk
30 {
31 
35 template <class TInputImage, class TOutputImage>
38 {
39  m_Lower = NumericTraits<InputImagePixelType>::NonpositiveMin();
40  m_Upper = NumericTraits<InputImagePixelType>::max();
41  m_ReplaceValue = NumericTraits<OutputImagePixelType>::One;
42  this->m_Connectivity = FaceConnectivity;
43 
44  typename InputPixelObjectType::Pointer lower = InputPixelObjectType::New();
45  lower->Set( NumericTraits< InputImagePixelType >::NonpositiveMin() );
46  this->ProcessObject::SetNthInput( 1, lower );
47 
48  typename InputPixelObjectType::Pointer upper = InputPixelObjectType::New();
49  upper->Set( NumericTraits< InputImagePixelType >::max() );
50  this->ProcessObject::SetNthInput( 2, upper );
51 }
52 
53 template <class TInputImage, class TOutputImage>
54 void
56 ::SetSeed ( const IndexType & seed )
57 {
58  this->ClearSeeds();
59  this->AddSeed ( seed );
60 }
61 
62 template <class TInputImage, class TOutputImage>
63 void
65 ::AddSeed(const IndexType & seed)
66 {
67  this->m_SeedList.push_back ( seed );
68  this->Modified();
69 }
70 
71 template <class TInputImage, class TOutputImage>
72 void
75 {
76  if( m_SeedList.size() > 0 )
77  {
78  this->m_SeedList.clear();
79  this->Modified();
80  }
81 }
82 
86 template <class TInputImage, class TOutputImage>
87 void
89 ::PrintSelf(std::ostream& os, Indent indent) const
90 {
91  this->Superclass::PrintSelf(os, indent);
92  os << indent << "Upper: "
93  << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_Upper)
94  << std::endl;
95  os << indent << "Lower: "
96  << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_Lower)
97  << std::endl;
98  os << indent << "ReplaceValue: "
99  << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_ReplaceValue)
100  << std::endl;
101  os << indent << "Connectivity: " << m_Connectivity << std::endl;
102 }
103 
104 template <class TInputImage, class TOutputImage>
105 void
108 {
109  Superclass::GenerateInputRequestedRegion();
110  if ( this->GetInput() )
111  {
112  InputImagePointer image =
113  const_cast< InputImageType * >( this->GetInput() );
114  image->SetRequestedRegionToLargestPossibleRegion();
115  }
116 }
117 
118 template <class TInputImage, class TOutputImage>
119 void
122 {
123  Superclass::EnlargeOutputRequestedRegion(output);
125 }
126 
127 template <class TInputImage, class TOutputImage>
128 void
131 {
132  if (input != this->GetLowerInput())
133  {
135  const_cast<InputPixelObjectType*>(input));
136  this->Modified();
137  }
138 }
139 
140 
141 template <class TInputImage, class TOutputImage>
142 void
145 {
146  if (input != this->GetUpperInput())
147  {
149  const_cast<InputPixelObjectType*>(input));
150  this->Modified();
151  }
152 }
153 
154 template <class TInputImage, class TOutputImage>
155 void
158 {
159  // first check to see if anything changed
160  typename InputPixelObjectType::Pointer upper=this->GetUpperInput();
161  if (upper && upper->Get() == threshold)
162  {
163  return;
164  }
165 
166  // create a data object to use as the input and to store this
167  // threshold. we always create a new data object to use as the input
168  // since we do not want to change the value in any current input
169  // (the current input could be the output of another filter or the
170  // current input could be used as an input to several filters)
171  upper = InputPixelObjectType::New();
172  this->ProcessObject::SetNthInput(2, upper);
173 
174  upper->Set(threshold);
175  this->Modified();
176 }
177 
178 
179 template <class TInputImage, class TOutputImage>
180 void
183 {
184  // first check to see if anything changed
185  typename InputPixelObjectType::Pointer lower=this->GetLowerInput();
186  if (lower && lower->Get() == threshold)
187  {
188  return;
189  }
190 
191  // create a data object to use as the input and to store this
192  // threshold. we always create a new data object to use as the input
193  // since we do not want to change the value in any current input
194  // (the current input could be the output of another filter or the
195  // current input could be used as an input to several filters)
196  lower = InputPixelObjectType::New();
197  this->ProcessObject::SetNthInput(1, lower);
198 
199  lower->Set(threshold);
200  this->Modified();
201 }
202 
203 
204 template <class TInputImage, class TOutputImage>
208 {
209  typename InputPixelObjectType::Pointer lower
210  = static_cast<InputPixelObjectType *>(this->ProcessObject::GetInput(1));
211  if (!lower)
212  {
213  // no input object available, create a new one and set it to the
214  // default threshold
215  lower = InputPixelObjectType::New();
216  lower->Set( NumericTraits<InputImagePixelType>::NonpositiveMin() );
217  this->ProcessObject::SetNthInput( 1, lower );
218  }
219 
220  return lower;
221 }
222 
223 
224 template <class TInputImage, class TOutputImage>
228 {
229  typename InputPixelObjectType::Pointer upper
230  = static_cast<InputPixelObjectType *>(this->ProcessObject::GetInput(2));
231  if (!upper)
232  {
233  // no input object available, create a new one and set it to the
234  // default threshold
235  upper = InputPixelObjectType::New();
236  upper->Set( NumericTraits<InputImagePixelType>::NonpositiveMin() );
237  this->ProcessObject::SetNthInput( 2, upper );
238  }
239 
240  return upper;
241 }
242 
243 
244 template <class TInputImage, class TOutputImage>
247 ::GetLower() const
248 {
249  typename InputPixelObjectType::Pointer lower
250  = const_cast<Self*>(this)->GetLowerInput();
251 
252  return lower->Get();
253 }
254 
255 template <class TInputImage, class TOutputImage>
258 ::GetUpper() const
259 {
260  typename InputPixelObjectType::Pointer upper
261  = const_cast<Self*>(this)->GetUpperInput();
262 
263  return upper->Get();
264 }
265 
266 template <class TInputImage, class TOutputImage>
267 void
270 {
271  InputImageConstPointer inputImage = this->GetInput();
272  OutputImagePointer outputImage = this->GetOutput();
273 
274  typename InputPixelObjectType::Pointer lowerThreshold=this->GetLowerInput();
275  typename InputPixelObjectType::Pointer upperThreshold=this->GetUpperInput();
276 
277  m_Lower = lowerThreshold->Get();
278  m_Upper = upperThreshold->Get();
279 
280  // Zero the output
281  OutputImageRegionType region = outputImage->GetRequestedRegion();
282  outputImage->SetBufferedRegion( region );
283  outputImage->Allocate();
284  outputImage->FillBuffer ( NumericTraits<OutputImagePixelType>::Zero );
285 
287 
288  typename FunctionType::Pointer function = FunctionType::New();
289  function->SetInputImage ( inputImage );
290  function->ThresholdBetween ( m_Lower, m_Upper );
291 
292  ProgressReporter progress(this, 0, region.GetNumberOfPixels());
293 
294  if (this->m_Connectivity == FaceConnectivity)
295  {
297  IteratorType it ( outputImage, function, m_SeedList );
298  it.GoToBegin();
299 
300  while( !it.IsAtEnd())
301  {
302  it.Set(m_ReplaceValue);
303  ++it;
304  progress.CompletedPixel(); // potential exception thrown here
305  }
306  }
307 
308 #ifdef ITK_USE_REVIEW
309  else if (this->m_Connectivity == FullConnectivity)
310  {
311  // use the fully connected iterator here. The fully connected iterator
312  // below is a superset of the above. However, it is reported to be 20%
313  // slower. Hence we use this "if" block to use the old iterator when
314  // we don't need full connectivity.
315 
317  IteratorType it ( outputImage, function, m_SeedList );
318  it.FullyConnectedOn();
319  it.GoToBegin();
320 
321  while( !it.IsAtEnd())
322  {
323  it.Set(m_ReplaceValue);
324  ++it;
325  progress.CompletedPixel(); // potential exception thrown here
326  }
327  }
328 #endif
329 
330 }
331 
332 
333 } // end namespace itk
334 
335 #endif

Generated at Sat Feb 2 2013 23:33:14 for Orfeo Toolbox with doxygen 1.8.1.1