OTB  10.0.0
Orfeo Toolbox
otbKMeansAttributesLabelMapFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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);
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:
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
Execute a KMeans on the attributes of a itk::LabelMap<otb::AttributesMapLabelObject>
itk::Statistics::KdTreeBasedKmeansEstimator< TreeType > EstimatorType
const CentroidsVectorType & GetCentroids() const
LabelMapToSampleListFilterType::MeasurementFunctorType MeasurementFunctorType
itk::Statistics::WeightedCentroidKdTreeGenerator< ListSampleType > TreeGeneratorType
itkGetObjectMacro(InputLabelMap, InputImageType)
itk::Statistics::ListSample< VectorType > ListSampleType
void operator=(const Self &)=delete
LabelObjectType::AttributesValueType AttributesValueType
void SetMeasurementFunctor(MeasurementFunctorType &functor)
itk::Statistics::EuclideanDistanceMetric< VectorType > DistanceType
LabelMapToSampleListFilterType::Pointer m_LabelMapToSampleListFilter
otb::LabelMapWithClassLabelToLabeledSampleListFilter< InputImageType, ListSampleType, TrainingListSampleType > LabelMapToSampleListFilterType
itk::VariableLengthVector< AttributesValueType > VectorType
itk::FixedArray< ClassLabelType, 1 > ClassLabelVectorType
itk::LabelMapFilter< TInputImage, TInputImage > Superclass
KMeansAttributesLabelMapFilter(const Self &)=delete
itk::Statistics::ListSample< ClassLabelVectorType > TrainingListSampleType
This class converts a LabelObjectMap with some class labeled objects to a SampleList and a TrainingSa...
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.