Orfeo Toolbox  3.16
InsightJournal/itkBinaryShapeKeepNObjectsImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkBinaryShapeKeepNObjectsImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2006/08/01 19:16:18 $
7  Version: $Revision: 1.7 $
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 __itkBinaryShapeKeepNObjectsImageFilter_txx
18 #define __itkBinaryShapeKeepNObjectsImageFilter_txx
19 
20 #include "itkBinaryShapeKeepNObjectsImageFilter.h"
21 #include "itkProgressAccumulator.h"
22 
23 
24 namespace itk {
25 
26 template<class TInputImage>
29 {
30  m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin();
31  m_ForegroundValue = NumericTraits<OutputImagePixelType>::max();
32  m_FullyConnected = false;
33  m_ReverseOrdering = false;
34  m_Attribute = LabelObjectType::SIZE;
35 }
36 
37 template<class TInputImage>
38 void
41 {
42  // call the superclass' implementation of this method
43  Superclass::GenerateInputRequestedRegion();
44 
45  // We need all the input.
46  InputImagePointer input = const_cast<InputImageType *>(this->GetInput());
47  if( input )
48  {
49  input->SetRequestedRegion( input->GetLargestPossibleRegion() );
50  }
51 }
52 
53 
54 template<class TInputImage>
55 void
58 {
59  this->GetOutput()
60  ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() );
61 }
62 
63 
64 template<class TInputImage>
65 void
68 {
69  // Create a process accumulator for tracking the progress of this minipipeline
71  progress->SetMiniPipelineFilter(this);
72 
73  // Allocate the output
74  this->AllocateOutputs();
75 
76  typename LabelizerType::Pointer labelizer = LabelizerType::New();
77  labelizer->SetInput( this->GetInput() );
78  labelizer->SetForegroundValue( m_ForegroundValue );
79  labelizer->SetBackgroundValue( m_BackgroundValue );
80  labelizer->SetFullyConnected( m_FullyConnected );
81  labelizer->SetNumberOfThreads( this->GetNumberOfThreads() );
82  progress->RegisterInternalFilter(labelizer, .3f);
83 
84  typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New();
85  valuator->SetInput( labelizer->GetOutput() );
86  valuator->SetNumberOfThreads( this->GetNumberOfThreads() );
87  if( m_Attribute == LabelObjectType::PERIMETER || m_Attribute == LabelObjectType::ROUNDNESS )
88  {
89  valuator->SetComputePerimeter( true );
90  }
91  if( m_Attribute == LabelObjectType::FERET_DIAMETER )
92  {
93  valuator->SetComputeFeretDiameter( true );
94  }
95  progress->RegisterInternalFilter(valuator, .3f);
96 
97  typename KeepNObjectsType::Pointer opening = KeepNObjectsType::New();
98  opening->SetInput( valuator->GetOutput() );
99  opening->SetNumberOfObjects( m_NumberOfObjects );
100  opening->SetReverseOrdering( m_ReverseOrdering );
101  opening->SetAttribute( m_Attribute );
102  opening->SetNumberOfThreads( this->GetNumberOfThreads() );
103  progress->RegisterInternalFilter(opening, .2f);
104 
105  typename BinarizerType::Pointer binarizer = BinarizerType::New();
106  binarizer->SetInput( opening->GetOutput() );
107  binarizer->SetForegroundValue( m_ForegroundValue );
108  binarizer->SetBackgroundValue( m_BackgroundValue );
109  binarizer->SetBackgroundImage( this->GetInput() );
110  binarizer->SetNumberOfThreads( this->GetNumberOfThreads() );
111  progress->RegisterInternalFilter(binarizer, .2f);
112 
113  binarizer->GraftOutput( this->GetOutput() );
114  binarizer->Update();
115  this->GraftOutput( binarizer->GetOutput() );
116 }
117 
118 
119 template<class TInputImage>
120 void
122 ::PrintSelf(std::ostream &os, Indent indent) const
123 {
124  Superclass::PrintSelf(os, indent);
125 
126  os << indent << "FullyConnected: " << m_FullyConnected << std::endl;
127  os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl;
128  os << indent << "ForegroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_ForegroundValue) << std::endl;
129  os << indent << "NumberOfObjects: " << m_NumberOfObjects << std::endl;
130  os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl;
131  os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl;
132 }
133 
134 }// end namespace itk
135 #endif

Generated at Sat Feb 2 2013 23:28:18 for Orfeo Toolbox with doxygen 1.8.1.1