Orfeo Toolbox  4.0
otbImageToLabelMapWithAttributesFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbImageToLabelMapWithAttributesFilter_txx
19 #define __otbImageToLabelMapWithAttributesFilter_txx
20 
22 #include "itkProcessObject.h"
23 
24 namespace otb
25 {
26 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
29 {
30  m_Output = LabelMapType::New();
32 }
33 
34 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
35 void
38 {
39  // call the superclass' implementation of this method
40  Superclass::GenerateInputRequestedRegion();
41 
42  // We need all the input.
43  typename InputImageType::Pointer input = const_cast< InputImageType * >( this->GetInput() );
44 
45  if ( !input )
46  { return; }
47 
48  input->SetRequestedRegion( input->GetLargestPossibleRegion() );
49 }
50 
51 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
52 void
54 ::SetInput( const InputImageType *image)
55 {
56  // Process object is not const-correct so the const_cast is required here
58  const_cast< InputImageType * >( image ) );
59 }
60 
61 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
62 void
65 {
66  // Process object is not const-correct so the const_cast is required here
68  const_cast<LabeledImageType * >( image ) );
69 
70 }
71 
72 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
76 {
77  if (this->GetNumberOfInputs() < 2)
78  {
79  return 0;
80  }
81 
82  return static_cast<const InputImageType* >
83  (this->itk::ProcessObject::GetInput(0) );
84 }
85 
86 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
90 {
91  if (this->GetNumberOfInputs() < 2)
92  {
93  return 0;
94  }
95 
96  return static_cast<const LabeledImageType* >
97  (this->itk::ProcessObject::GetInput(1) );
98 }
99 
100 
101 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
103 ::LabelMapType*
106 {
107  return dynamic_cast< LabelMapType* >
108  (this->Superclass::GetOutput(0));
109 }
110 
111 
112 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
113 void
116 {
117  typename InputImageType::Pointer inputImage = const_cast<InputImageType *>(this->GetInput());
118  typename LabeledImageType::Pointer labeldImage = const_cast<LabeledImageType *>(this->GetLabeledImage());
119 
120  // Convert to label map
121  typename LabelMapFilterType::Pointer lfilter = LabelMapFilterType::New();
122  lfilter->SetBackgroundValue(itk::NumericTraits<LabelType>::max());
123  lfilter->SetInput(labeldImage);
124 
125  // Compute shape attributes
126  typename ShapeLabelMapFilterType::Pointer shapeLabelMapFilter = ShapeLabelMapFilterType::New();
127  shapeLabelMapFilter->SetInput(lfilter->GetOutput());
128 
129  // Compute radiometric attributes
130  typename BandStatisticsLabelMapFilterType::Pointer bandStatsLabelMapFilter = BandStatisticsLabelMapFilterType::New();
131  bandStatsLabelMapFilter->SetInput(shapeLabelMapFilter->GetOutput());
132  bandStatsLabelMapFilter->SetFeatureImage(inputImage);
133 
134  // Get the label map
135  bandStatsLabelMapFilter->GetOutput()->SetAdjacencyMap(lfilter->GetOutput()->GetAdjacencyMap());
136  bandStatsLabelMapFilter->GraftOutput( this->GetOutput() );
137 
138  // execute the mini-pipeline
139  bandStatsLabelMapFilter->Update();
140 
141  // graft the mini-pipeline output back onto this filter's output.
142  this->GraftOutput( bandStatsLabelMapFilter->GetOutput() );
143 }
144 
145 
146 }
147 
148 #endif

Generated at Sat Mar 8 2014 16:01:35 for Orfeo Toolbox with doxygen 1.8.3.1