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

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