OTB  10.0.0
Orfeo Toolbox
otbKMeansImageClassificationFilter.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 otbKMeansImageClassificationFilter_h
22 #define otbKMeansImageClassificationFilter_h
23 
24 #include "itkInPlaceImageFilter.h"
25 #include "itkListSample.h"
26 #include "itkEuclideanDistanceMetric.h"
27 
28 namespace otb
29 {
44 template <class TInputImage, class TOutputImage, unsigned int VMaxSampleDimension = 10, class TMaskImage = TOutputImage>
45 class ITK_EXPORT KMeansImageClassificationFilter : public itk::InPlaceImageFilter<TInputImage, TOutputImage>
46 {
47 public:
50  typedef itk::InPlaceImageFilter<TInputImage, TOutputImage> Superclass;
51  typedef itk::SmartPointer<Self> Pointer;
52  typedef itk::SmartPointer<const Self> ConstPointer;
53 
55  itkNewMacro(Self);
56 
58  itkTypeMacro(KMeansImageClassificationFilter, InPlaceImageFilter);
59 
64  itkStaticConstMacro(MaxSampleDimension, unsigned int, VMaxSampleDimension);
65 
66  typedef TInputImage InputImageType;
67  typedef typename InputImageType::ConstPointer InputImageConstPointerType;
68  typedef typename InputImageType::InternalPixelType ValueType;
69 
70  typedef TMaskImage MaskImageType;
71  typedef typename MaskImageType::ConstPointer MaskImageConstPointerType;
72  typedef typename MaskImageType::Pointer MaskImagePointerType;
73 
74  typedef TOutputImage OutputImageType;
75  typedef typename OutputImageType::Pointer OutputImagePointerType;
76  typedef typename OutputImageType::RegionType OutputImageRegionType;
77  typedef typename OutputImageType::PixelType LabelType;
78 
79  typedef itk::FixedArray<ValueType, MaxSampleDimension> SampleType;
80  typedef itk::Array<double> KMeansParametersType;
81  typedef std::map<LabelType, SampleType> CentroidsMapType;
82  typedef itk::Statistics::EuclideanDistanceMetric<SampleType> DistanceType;
83 
85  itkSetMacro(Centroids, KMeansParametersType);
86  itkGetConstReferenceMacro(Centroids, KMeansParametersType);
88 
90  itkSetMacro(DefaultLabel, LabelType);
91  itkGetMacro(DefaultLabel, LabelType);
93 
98  void SetInputMask(const MaskImageType* mask);
99 
105 
106 protected:
109 
111  ~KMeansImageClassificationFilter() override = default;
112 
114  void DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread) override;
115 
117  void BeforeThreadedGenerateData() override;
118 
120  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
121 
122 private:
124  void operator=(const Self&) = delete;
125 
128 
131 
134 };
135 } // End namespace otb
136 #ifndef OTB_MANUAL_INSTANTIATION
138 #endif
139 
140 #endif
This filter performs the classification of a VectorImage using a KMeans estimation result.
~KMeansImageClassificationFilter() override=default
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void SetInputMask(const MaskImageType *mask)
std::map< LabelType, SampleType > CentroidsMapType
KMeansImageClassificationFilter(const Self &)=delete
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
itk::Statistics::EuclideanDistanceMetric< SampleType > DistanceType
itk::InPlaceImageFilter< TInputImage, TOutputImage > Superclass
const MaskImageType * GetInputMask(void)
itk::FixedArray< ValueType, MaxSampleDimension > SampleType
void operator=(const Self &)=delete
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.