OTB  10.0.0
Orfeo Toolbox
otbImageClassificationFilter.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 otbImageClassificationFilter_h
22 #define otbImageClassificationFilter_h
23 
24 #include "itkImageToImageFilter.h"
26 #include "otbImage.h"
27 #include "otbVectorImage.h"
28 
29 namespace otb
30 {
43 template <class TInputImage, class TOutputImage, class TMaskImage = TOutputImage>
44 class ITK_EXPORT ImageClassificationFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
45 {
46 public:
49  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
50  typedef itk::SmartPointer<Self> Pointer;
51  typedef itk::SmartPointer<const Self> ConstPointer;
52 
54  itkNewMacro(Self);
55 
57  itkTypeMacro(ImageClassificationFilter, ImageToImageFilter);
58 
59  typedef TInputImage InputImageType;
60  typedef typename InputImageType::ConstPointer InputImageConstPointerType;
61  typedef typename InputImageType::InternalPixelType ValueType;
62 
63  typedef TMaskImage MaskImageType;
64  typedef typename MaskImageType::ConstPointer MaskImageConstPointerType;
65  typedef typename MaskImageType::Pointer MaskImagePointerType;
66 
67  typedef TOutputImage OutputImageType;
68  typedef typename OutputImageType::Pointer OutputImagePointerType;
69  typedef typename OutputImageType::RegionType OutputImageRegionType;
70  typedef typename OutputImageType::PixelType LabelType;
71 
74 
77 
80 
82  typedef itk::VariableLengthVector<double> ProbaSampleType;
84  itkSetObjectMacro(Model, ModelType);
87 
89  itkSetMacro(DefaultLabel, LabelType);
90  itkGetMacro(DefaultLabel, LabelType);
92 
94  itkSetMacro(UseConfidenceMap, bool);
95  itkGetMacro(UseConfidenceMap, bool);
97 
99  itkSetMacro(UseProbaMap, bool);
100  itkGetMacro(UseProbaMap, bool);
102 
103  itkSetMacro(BatchMode, bool);
104  itkGetMacro(BatchMode, bool);
105  itkBooleanMacro(BatchMode);
106 
107  itkSetMacro(NumberOfClasses, unsigned int);
108  itkGetMacro(NumberOfClasses, unsigned int);
114  void SetInputMask(const MaskImageType* mask);
115 
121 
128 
129 protected:
132 
135  {
136  }
137 
139  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
140  void ClassicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId);
141  void BatchThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId);
142 
144  void BeforeThreadedGenerateData() override;
145 
147  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
148 
150  {
151  Superclass::GenerateOutputInformation();
152  // Define the number of output bands
153  this->GetOutputProba()->SetNumberOfComponentsPerPixel(m_NumberOfClasses);
154  }
155 
156 private:
157  ImageClassificationFilter(const Self&) = delete;
158  void operator=(const Self&) = delete;
159 
162 
165 
170  unsigned int m_NumberOfClasses;
171 };
172 } // End namespace otb
173 #ifndef OTB_MANUAL_INSTANTIATION
175 #endif
176 
177 #endif
This filter performs the classification of a VectorImage using a Model.
ImageClassificationFilter(const Self &)=delete
OutputImageType::RegionType OutputImageRegionType
void BatchThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
OutputImageType::Pointer OutputImagePointerType
InputImageType::InternalPixelType ValueType
void operator=(const Self &)=delete
MachineLearningModel< ValueType, LabelType > ModelType
void SetInputMask(const MaskImageType *mask)
ConfidenceImageType::Pointer ConfidenceImagePointerType
InputImageType::ConstPointer InputImageConstPointerType
itk::SmartPointer< const Self > ConstPointer
const MaskImageType * GetInputMask(void)
void ClassicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
otb::VectorImage< double > ProbaImageType
itk::VariableLengthVector< double > ProbaSampleType
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
ConfidenceImageType * GetOutputConfidence(void)
ProbaImageType * GetOutputProba(void)
itkGetObjectMacro(Model, ModelType)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
MaskImageType::ConstPointer MaskImageConstPointerType
void BeforeThreadedGenerateData() override
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:92
itk::SmartPointer< Self > Pointer
Definition: otbImage.h:97
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
itk::SmartPointer< Self > Pointer
Creation of an "otb" vector image which contains metadata.
itk::SmartPointer< Self > Pointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.