Orfeo Toolbox  3.16
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
37 ::SetInput( const InputImageType *image)
38 {
39  // Process object is not const-correct so the const_cast is required here
41  const_cast< InputImageType * >( image ) );
42 }
43 
44 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
45 void
48 {
49  // Process object is not const-correct so the const_cast is required here
51  const_cast<LabeledImageType * >( image ) );
52 
53 }
54 
55 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
59 {
60  if (this->GetNumberOfInputs() < 2)
61  {
62  return 0;
63  }
64 
65  return static_cast<const InputImageType* >
66  (this->itk::ProcessObject::GetInput(0) );
67 }
68 
69 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
73 {
74  if (this->GetNumberOfInputs() < 2)
75  {
76  return 0;
77  }
78 
79  return static_cast<const LabeledImageType* >
80  (this->itk::ProcessObject::GetInput(1) );
81 }
82 
83 
84 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
86 ::LabelMapType*
89 {
90  return dynamic_cast< LabelMapType* >
91  (this->Superclass::GetOutput(0));
92 }
93 
94 
95 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
96 void
99 {
100  typename InputImageType::Pointer inputImage = const_cast<InputImageType *>(this->GetInput());
101  typename LabeledImageType::Pointer labeldImage = const_cast<LabeledImageType *>(this->GetLabeledImage());
102 
103  // Convert to label map
104  typename LabelMapFilterType::Pointer lfilter = LabelMapFilterType::New();
105  lfilter->SetBackgroundValue(itk::NumericTraits<LabelType>::max());
106  lfilter->SetInput(labeldImage);
107 
108  // Compute shape attributes
109  typename ShapeLabelMapFilterType::Pointer shapeLabelMapFilter = ShapeLabelMapFilterType::New();
110  shapeLabelMapFilter->SetInput(lfilter->GetOutput());
111 
112  // Compute radiometric attributes
113  typename BandStatisticsLabelMapFilterType::Pointer bandStatsLabelMapFilter = BandStatisticsLabelMapFilterType::New();
114  bandStatsLabelMapFilter->SetInput(shapeLabelMapFilter->GetOutput());
115  bandStatsLabelMapFilter->SetFeatureImage(inputImage);
116 
117  // Get the label map
118  bandStatsLabelMapFilter->GetOutput()->SetAdjacencyMap(lfilter->GetOutput()->GetAdjacencyMap());
119  bandStatsLabelMapFilter->GraftOutput( this->GetOutput() );
120 
121  // execute the mini-pipeline
122  bandStatsLabelMapFilter->Update();
123 
124  // graft the mini-pipeline output back onto this filter's output.
125  this->GraftOutput( bandStatsLabelMapFilter->GetOutput() );
126 }
127 
128 
129 }
130 
131 #endif

Generated at Sun May 12 2013 00:32:46 for Orfeo Toolbox with doxygen 1.8.3.1