OTB  9.0.0
Orfeo Toolbox
otbImageClassificationFilter.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 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);
85  itkGetObjectMacro(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 
120  const MaskImageType* GetInputMask(void);
121 
125  ConfidenceImageType* GetOutputConfidence(void);
126  ProbaImageType* GetOutputProba(void);
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
otb::ImageClassificationFilter::InputImageType
TInputImage InputImageType
Definition: otbImageClassificationFilter.h:57
otb::ImageClassificationFilter::MaskImagePointerType
MaskImageType::Pointer MaskImagePointerType
Definition: otbImageClassificationFilter.h:65
otb::ImageClassificationFilter::ConfidenceImageType
otb::Image< double > ConfidenceImageType
Definition: otbImageClassificationFilter.h:75
otbVectorImage.h
otb::ImageClassificationFilter
This filter performs the classification of a VectorImage using a Model.
Definition: otbImageClassificationFilter.h:44
otb::ImageClassificationFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbImageClassificationFilter.h:67
otb::ImageClassificationFilter::ProbaSampleType
itk::VariableLengthVector< double > ProbaSampleType
Definition: otbImageClassificationFilter.h:82
otb::ImageClassificationFilter::MaskImageConstPointerType
MaskImageType::ConstPointer MaskImageConstPointerType
Definition: otbImageClassificationFilter.h:64
otb::VectorImage::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbVectorImage.h:53
otbImage.h
otb::ImageClassificationFilter::m_DefaultLabel
LabelType m_DefaultLabel
Definition: otbImageClassificationFilter.h:164
otb::ImageClassificationFilter::m_BatchMode
bool m_BatchMode
Definition: otbImageClassificationFilter.h:169
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::ImageClassificationFilter::ConfidenceImagePointerType
ConfidenceImageType::Pointer ConfidenceImagePointerType
Definition: otbImageClassificationFilter.h:76
otb::ImageClassificationFilter::ModelType
MachineLearningModel< ValueType, LabelType > ModelType
Definition: otbImageClassificationFilter.h:72
otb::ImageClassificationFilter::ProbaImagePointerType
ProbaImageType::Pointer ProbaImagePointerType
Definition: otbImageClassificationFilter.h:81
otb::ImageClassificationFilter::ProbaImageType
otb::VectorImage< double > ProbaImageType
Definition: otbImageClassificationFilter.h:79
otb::ImageClassificationFilter::LabelType
OutputImageType::PixelType LabelType
Definition: otbImageClassificationFilter.h:70
otb::ImageClassificationFilter::m_Model
ModelPointerType m_Model
Definition: otbImageClassificationFilter.h:161
otbMachineLearningModel.h
otb::ImageClassificationFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbImageClassificationFilter.h:69
otb::ImageClassificationFilter::InputImageConstPointerType
InputImageType::ConstPointer InputImageConstPointerType
Definition: otbImageClassificationFilter.h:60
otb::ImageClassificationFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbImageClassificationFilter.h:149
otb::ImageClassificationFilter::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbImageClassificationFilter.h:49
otb::ImageClassificationFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageClassificationFilter.h:50
otb::ImageClassificationFilter::m_UseProbaMap
bool m_UseProbaMap
Definition: otbImageClassificationFilter.h:168
otb::ImageClassificationFilter::~ImageClassificationFilter
~ImageClassificationFilter() override
Definition: otbImageClassificationFilter.h:134
otb::MachineLearningModel::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbMachineLearningModel.h:77
otb::MachineLearningModel
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
Definition: otbMachineLearningModel.h:70
otb::ImageClassificationFilter::OutputImagePointerType
OutputImageType::Pointer OutputImagePointerType
Definition: otbImageClassificationFilter.h:68
otb::ImageClassificationFilter::Self
ImageClassificationFilter Self
Definition: otbImageClassificationFilter.h:48
otb::ImageClassificationFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageClassificationFilter.h:51
otb::ImageClassificationFilter::MaskImageType
TMaskImage MaskImageType
Definition: otbImageClassificationFilter.h:63
otb::ImageClassificationFilter::ValueType
InputImageType::InternalPixelType ValueType
Definition: otbImageClassificationFilter.h:61
otb::ImageClassificationFilter::m_NumberOfClasses
unsigned int m_NumberOfClasses
Definition: otbImageClassificationFilter.h:170
otb::Image::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImage.h:97
otbImageClassificationFilter.hxx
otb::ImageClassificationFilter::ModelPointerType
ModelType::Pointer ModelPointerType
Definition: otbImageClassificationFilter.h:73
otb::ImageClassificationFilter::m_UseConfidenceMap
bool m_UseConfidenceMap
Definition: otbImageClassificationFilter.h:167
otb::VectorImage
Creation of an "otb" vector image which contains metadata.
Definition: otbVectorImage.h:45