OTB  9.0.0
Orfeo Toolbox
otbKMeansAttributesLabelMapFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbKMeansAttributesLabelMapFilter_h
22 #define otbKMeansAttributesLabelMapFilter_h
23 
24 #include "itkLabelMapFilter.h"
26 #include "itkListSample.h"
27 #include "itkWeightedCentroidKdTreeGenerator.h"
28 #include "itkKdTreeBasedKmeansEstimator.h"
29 
30 namespace otb
31 {
32 
38 template <class TInputImage>
39 class ITK_EXPORT KMeansAttributesLabelMapFilter : public itk::Object
40 {
41 public:
44  typedef itk::LabelMapFilter<TInputImage, TInputImage> Superclass;
45  typedef itk::SmartPointer<Self> Pointer;
46  typedef itk::SmartPointer<const Self> ConstPointer;
47 
49  typedef TInputImage InputImageType;
50  typedef typename InputImageType::Pointer InputImagePointer;
51  typedef typename InputImageType::ConstPointer InputImageConstPointer;
52  typedef typename InputImageType::RegionType InputImageRegionType;
53  typedef typename InputImageType::PixelType InputImagePixelType;
54  typedef typename InputImageType::LabelObjectType LabelObjectType;
55  typedef itk::DataObject DataObjectType;
56  typedef DataObjectType::Pointer DataObjectPointerType;
57 
58  // LabelObject attributes
59  typedef typename LabelObjectType::AttributesValueType AttributesValueType;
60  typedef typename LabelObjectType::ClassLabelType ClassLabelType;
61 
62  // LabelMapToSampleList
63  typedef itk::VariableLengthVector<AttributesValueType> VectorType;
64  typedef itk::FixedArray<ClassLabelType, 1> ClassLabelVectorType;
65 
66  typedef itk::Statistics::ListSample<VectorType> ListSampleType;
67  typedef itk::Statistics::ListSample<ClassLabelVectorType> TrainingListSampleType;
70 
71  // KMeans
72  typedef itk::Statistics::WeightedCentroidKdTreeGenerator<ListSampleType> TreeGeneratorType;
73  typedef typename TreeGeneratorType::KdTreeType TreeType;
74  typedef itk::Statistics::KdTreeBasedKmeansEstimator<TreeType> EstimatorType;
75  typedef itk::Statistics::EuclideanDistanceMetric<VectorType> DistanceType;
76  typedef std::vector<VectorType> CentroidsVectorType;
77 
79  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
80 
82  itkNewMacro(Self);
83 
85  itkTypeMacro(KMeansAttributesLabelMapFilter, itk::Object);
86 
89  {
90  return m_Centroids;
91  }
93  {
94  return m_Centroids;
95  }
97 
98  itkSetObjectMacro(InputLabelMap, InputImageType);
99  itkGetObjectMacro(InputLabelMap, InputImageType);
100 
105  itkSetMacro(NumberOfClasses, unsigned int);
106  itkGetMacro(NumberOfClasses, unsigned int);
108 
110  {
111  return m_LabelMapToSampleListFilter->GetMeasurementFunctor();
112  }
113 
115  {
116  m_LabelMapToSampleListFilter->SetMeasurementFunctor(functor);
117  }
118 
119  void Compute();
120 
121 protected:
124 
125 
126 private:
127  KMeansAttributesLabelMapFilter(const Self&) = delete;
128  void operator=(const Self&) = delete;
129 
132 
134  unsigned int m_NumberOfClasses;
135 
136 }; // end of class
137 
138 } // end namespace otb
139 
140 #ifndef OTB_MANUAL_INSTANTIATION
142 #endif
143 
144 #endif
otb::LabelMapWithClassLabelToLabeledSampleListFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbLabelMapWithClassLabelToLabeledSampleListFilter.h:51
otb::KMeansAttributesLabelMapFilter::ClassLabelType
LabelObjectType::ClassLabelType ClassLabelType
Definition: otbKMeansAttributesLabelMapFilter.h:60
otb::KMeansAttributesLabelMapFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbKMeansAttributesLabelMapFilter.h:46
otb::KMeansAttributesLabelMapFilter::SetMeasurementFunctor
void SetMeasurementFunctor(MeasurementFunctorType &functor)
Definition: otbKMeansAttributesLabelMapFilter.h:114
otbKMeansAttributesLabelMapFilter.hxx
otb::KMeansAttributesLabelMapFilter::m_LabelMapToSampleListFilter
LabelMapToSampleListFilterType::Pointer m_LabelMapToSampleListFilter
Definition: otbKMeansAttributesLabelMapFilter.h:133
otb::KMeansAttributesLabelMapFilter::TrainingListSampleType
itk::Statistics::ListSample< ClassLabelVectorType > TrainingListSampleType
Definition: otbKMeansAttributesLabelMapFilter.h:67
otb::KMeansAttributesLabelMapFilter::TreeType
TreeGeneratorType::KdTreeType TreeType
Definition: otbKMeansAttributesLabelMapFilter.h:73
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::LabelMapWithClassLabelToLabeledSampleListFilter
This class converts a LabelObjectMap with some class labeled objects to a SampleList and a TrainingSa...
Definition: otbLabelMapWithClassLabelToLabeledSampleListFilter.h:45
otb::KMeansAttributesLabelMapFilter::InputImagePointer
InputImageType::Pointer InputImagePointer
Definition: otbKMeansAttributesLabelMapFilter.h:50
otb::KMeansAttributesLabelMapFilter::ListSampleType
itk::Statistics::ListSample< VectorType > ListSampleType
Definition: otbKMeansAttributesLabelMapFilter.h:66
otbLabelMapWithClassLabelToLabeledSampleListFilter.h
otb::KMeansAttributesLabelMapFilter::m_InputLabelMap
InputImagePointer m_InputLabelMap
Definition: otbKMeansAttributesLabelMapFilter.h:130
otb::KMeansAttributesLabelMapFilter::Superclass
itk::LabelMapFilter< TInputImage, TInputImage > Superclass
Definition: otbKMeansAttributesLabelMapFilter.h:44
otb::KMeansAttributesLabelMapFilter::InputImageConstPointer
InputImageType::ConstPointer InputImageConstPointer
Definition: otbKMeansAttributesLabelMapFilter.h:51
otb::KMeansAttributesLabelMapFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbKMeansAttributesLabelMapFilter.h:45
otb::KMeansAttributesLabelMapFilter::m_Centroids
CentroidsVectorType m_Centroids
Definition: otbKMeansAttributesLabelMapFilter.h:131
otb::LabelMapWithClassLabelToLabeledSampleListFilter::MeasurementFunctorType
TMeasurementFunctor MeasurementFunctorType
Definition: otbLabelMapWithClassLabelToLabeledSampleListFilter.h:78
otb::KMeansAttributesLabelMapFilter::m_NumberOfClasses
unsigned int m_NumberOfClasses
Definition: otbKMeansAttributesLabelMapFilter.h:134
otb::KMeansAttributesLabelMapFilter::MeasurementFunctorType
LabelMapToSampleListFilterType::MeasurementFunctorType MeasurementFunctorType
Definition: otbKMeansAttributesLabelMapFilter.h:69
otb::KMeansAttributesLabelMapFilter::GetCentroids
CentroidsVectorType & GetCentroids()
Definition: otbKMeansAttributesLabelMapFilter.h:88
otb::KMeansAttributesLabelMapFilter
Execute a KMeans on the attributes of a itk::LabelMap<otb::AttributesMapLabelObject>
Definition: otbKMeansAttributesLabelMapFilter.h:39
otb::KMeansAttributesLabelMapFilter::ClassLabelVectorType
itk::FixedArray< ClassLabelType, 1 > ClassLabelVectorType
Definition: otbKMeansAttributesLabelMapFilter.h:64
otb::KMeansAttributesLabelMapFilter::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbKMeansAttributesLabelMapFilter.h:53
otb::KMeansAttributesLabelMapFilter::AttributesValueType
LabelObjectType::AttributesValueType AttributesValueType
Definition: otbKMeansAttributesLabelMapFilter.h:59
otb::KMeansAttributesLabelMapFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbKMeansAttributesLabelMapFilter.h:52
otb::KMeansAttributesLabelMapFilter::CentroidsVectorType
std::vector< VectorType > CentroidsVectorType
Definition: otbKMeansAttributesLabelMapFilter.h:76
otb::KMeansAttributesLabelMapFilter::GetCentroids
const CentroidsVectorType & GetCentroids() const
Definition: otbKMeansAttributesLabelMapFilter.h:92
otb::KMeansAttributesLabelMapFilter::EstimatorType
itk::Statistics::KdTreeBasedKmeansEstimator< TreeType > EstimatorType
Definition: otbKMeansAttributesLabelMapFilter.h:74
otb::KMeansAttributesLabelMapFilter::DataObjectType
itk::DataObject DataObjectType
Definition: otbKMeansAttributesLabelMapFilter.h:55
otb::KMeansAttributesLabelMapFilter::LabelObjectType
InputImageType::LabelObjectType LabelObjectType
Definition: otbKMeansAttributesLabelMapFilter.h:54
otb::KMeansAttributesLabelMapFilter::Self
KMeansAttributesLabelMapFilter Self
Definition: otbKMeansAttributesLabelMapFilter.h:43
otb::KMeansAttributesLabelMapFilter::DistanceType
itk::Statistics::EuclideanDistanceMetric< VectorType > DistanceType
Definition: otbKMeansAttributesLabelMapFilter.h:75
otb::KMeansAttributesLabelMapFilter::VectorType
itk::VariableLengthVector< AttributesValueType > VectorType
Definition: otbKMeansAttributesLabelMapFilter.h:63
otb::KMeansAttributesLabelMapFilter::LabelMapToSampleListFilterType
otb::LabelMapWithClassLabelToLabeledSampleListFilter< InputImageType, ListSampleType, TrainingListSampleType > LabelMapToSampleListFilterType
Definition: otbKMeansAttributesLabelMapFilter.h:68
otb::KMeansAttributesLabelMapFilter::DataObjectPointerType
DataObjectType::Pointer DataObjectPointerType
Definition: otbKMeansAttributesLabelMapFilter.h:56
otb::KMeansAttributesLabelMapFilter::~KMeansAttributesLabelMapFilter
~KMeansAttributesLabelMapFilter() override
Definition: otbKMeansAttributesLabelMapFilter.h:123
otb::KMeansAttributesLabelMapFilter::GetMeasurementFunctor
MeasurementFunctorType & GetMeasurementFunctor()
Definition: otbKMeansAttributesLabelMapFilter.h:109
otb::KMeansAttributesLabelMapFilter::TreeGeneratorType
itk::Statistics::WeightedCentroidKdTreeGenerator< ListSampleType > TreeGeneratorType
Definition: otbKMeansAttributesLabelMapFilter.h:72
otb::KMeansAttributesLabelMapFilter::InputImageType
TInputImage InputImageType
Definition: otbKMeansAttributesLabelMapFilter.h:49