OTB  9.0.0
Orfeo Toolbox
otbKMeansImageClassificationFilter.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 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 
104  const MaskImageType* GetInputMask(void);
105 
106 protected:
109 
111  ~KMeansImageClassificationFilter() override = default;
112 
114  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
115 
117  void BeforeThreadedGenerateData() override;
118 
120  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
121 
122 private:
123  KMeansImageClassificationFilter(const Self&) = delete;
124  void operator=(const Self&) = delete;
125 
128 
131 
134 };
135 } // End namespace otb
136 #ifndef OTB_MANUAL_INSTANTIATION
138 #endif
139 
140 #endif
otb::KMeansImageClassificationFilter::MaskImagePointerType
MaskImageType::Pointer MaskImagePointerType
Definition: otbKMeansImageClassificationFilter.h:72
otb::KMeansImageClassificationFilter::Superclass
itk::InPlaceImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbKMeansImageClassificationFilter.h:50
otb::KMeansImageClassificationFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbKMeansImageClassificationFilter.h:52
otb::KMeansImageClassificationFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbKMeansImageClassificationFilter.h:76
otb::KMeansImageClassificationFilter::LabelType
OutputImageType::PixelType LabelType
Definition: otbKMeansImageClassificationFilter.h:77
otb::KMeansImageClassificationFilter::MaskImageConstPointerType
MaskImageType::ConstPointer MaskImageConstPointerType
Definition: otbKMeansImageClassificationFilter.h:71
otb::KMeansImageClassificationFilter::InputImageType
TInputImage InputImageType
Definition: otbKMeansImageClassificationFilter.h:66
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::KMeansImageClassificationFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbKMeansImageClassificationFilter.h:74
otbKMeansImageClassificationFilter.hxx
otb::KMeansImageClassificationFilter::m_DefaultLabel
LabelType m_DefaultLabel
Definition: otbKMeansImageClassificationFilter.h:130
otb::KMeansImageClassificationFilter::InputImageConstPointerType
InputImageType::ConstPointer InputImageConstPointerType
Definition: otbKMeansImageClassificationFilter.h:67
otb::KMeansImageClassificationFilter::SampleType
itk::FixedArray< ValueType, MaxSampleDimension > SampleType
Definition: otbKMeansImageClassificationFilter.h:79
otb::KMeansImageClassificationFilter::m_CentroidsMap
CentroidsMapType m_CentroidsMap
Definition: otbKMeansImageClassificationFilter.h:133
otb::KMeansImageClassificationFilter::m_Centroids
KMeansParametersType m_Centroids
Definition: otbKMeansImageClassificationFilter.h:127
otb::KMeansImageClassificationFilter
This filter performs the classification of a VectorImage using a KMeans estimation result.
Definition: otbKMeansImageClassificationFilter.h:45
otb::KMeansImageClassificationFilter::CentroidsMapType
std::map< LabelType, SampleType > CentroidsMapType
Definition: otbKMeansImageClassificationFilter.h:81
otb::KMeansImageClassificationFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbKMeansImageClassificationFilter.h:51
otb::KMeansImageClassificationFilter::Self
KMeansImageClassificationFilter Self
Definition: otbKMeansImageClassificationFilter.h:49
otb::KMeansImageClassificationFilter::KMeansParametersType
itk::Array< double > KMeansParametersType
Definition: otbKMeansImageClassificationFilter.h:80
otb::KMeansImageClassificationFilter::DistanceType
itk::Statistics::EuclideanDistanceMetric< SampleType > DistanceType
Definition: otbKMeansImageClassificationFilter.h:82
otb::KMeansImageClassificationFilter::ValueType
InputImageType::InternalPixelType ValueType
Definition: otbKMeansImageClassificationFilter.h:68
otb::KMeansImageClassificationFilter::MaskImageType
TMaskImage MaskImageType
Definition: otbKMeansImageClassificationFilter.h:70
otb::KMeansImageClassificationFilter::OutputImagePointerType
OutputImageType::Pointer OutputImagePointerType
Definition: otbKMeansImageClassificationFilter.h:75