OTB  9.0.0
Orfeo Toolbox
otbConfusionMatrixCalculator.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 
22 #ifndef otbConfusionMatrixCalculator_h
23 #define otbConfusionMatrixCalculator_h
24 
25 #include "otbMacro.h"
27 
28 namespace otb
29 {
57 template <class TRefListLabel, class TProdListLabel>
58 class ITK_EXPORT ConfusionMatrixCalculator : public itk::Object
59 {
60 public:
63  typedef itk::Object Superclass;
64  typedef itk::SmartPointer<Self> Pointer;
65  typedef itk::SmartPointer<const Self> ConstPointer;
66 
68  itkTypeMacro(ConfusionMatrixCalculator, itk::Object);
69 
71  itkNewMacro(Self);
72 
74  typedef TRefListLabel RefListLabelType;
75  typedef typename RefListLabelType::Pointer RefListLabelPointerType;
76 
77  typedef TProdListLabel ProdListLabelType;
78  typedef typename ProdListLabelType::Pointer ProdListLabelPointerType;
79 
80  typedef typename RefListLabelType::ValueType::ValueType ClassLabelType;
81  typedef std::map<ClassLabelType, int> MapOfClassesType;
82  typedef std::map<int, ClassLabelType> MapOfIndicesType;
83 
85  typedef itk::VariableSizeMatrix<unsigned long> ConfusionMatrixType;
86 
89 
91  typedef itk::VariableLengthVector<double> MeasurementType;
92 
94  void Compute(void);
95 
97  itkSetObjectMacro(ReferenceLabels, RefListLabelType);
98  itkGetConstObjectMacro(ReferenceLabels, RefListLabelType);
99  itkSetObjectMacro(ProducedLabels, ProdListLabelType);
100  itkGetConstObjectMacro(ProducedLabels, ProdListLabelType);
101  itkGetMacro(TruePositiveValues, MeasurementType);
102  itkGetMacro(TrueNegativeValues, MeasurementType);
103  itkGetMacro(FalsePositiveValues, MeasurementType);
104  itkGetMacro(FalseNegativeValues, MeasurementType);
105  itkGetMacro(TruePositiveValue, double);
106  itkGetMacro(TrueNegativeValue, double);
107  itkGetMacro(FalsePositiveValue, double);
108  itkGetMacro(FalseNegativeValue, double);
109  itkGetMacro(KappaIndex, double);
110  itkGetMacro(OverallAccuracy, double);
111  itkGetMacro(Precisions, MeasurementType);
112  itkGetMacro(Recalls, MeasurementType);
113  itkGetMacro(FScores, MeasurementType);
114  itkGetMacro(Precision, double);
115  itkGetMacro(Recall, double);
116  itkGetMacro(FScore, double);
117  itkGetMacro(NumberOfClasses, unsigned short);
118  itkGetMacro(NumberOfSamples, unsigned long);
119  itkGetMacro(ConfusionMatrix, ConfusionMatrixType);
121 
122  /* Gives the correspondence between a class label
123  * and its index in the confusion matrix
124  */
126  {
127  return m_MapOfClasses;
128  }
129 
130  /* Gives the correspondence between an index in the
131  * confusion matrix and the class label
132  */
134  {
135  return m_MapOfIndices;
136  }
137 
138 protected:
141  {
142  }
143  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
144 
145 
146 private:
147  ConfusionMatrixCalculator(const Self&) = delete;
148  void operator=(const Self&) = delete;
149 
150  double m_KappaIndex;
152 
157 
161 
166 
167  double m_Precision;
168  double m_Recall;
169  double m_FScore;
170 
173 
174  unsigned short m_NumberOfClasses;
175  unsigned long m_NumberOfSamples;
176 
179 
182 };
183 } // end of namespace otb
184 
185 #ifndef OTB_MANUAL_INSTANTIATION
187 #endif
188 
189 #endif
otb::ConfusionMatrixCalculator::ConfusionMatrixMeasurementsType
otb::ConfusionMatrixMeasurements< ConfusionMatrixType, ClassLabelType > ConfusionMatrixMeasurementsType
Definition: otbConfusionMatrixCalculator.h:88
otb::ConfusionMatrixCalculator::m_KappaIndex
double m_KappaIndex
Definition: otbConfusionMatrixCalculator.h:150
otb::ConfusionMatrixCalculator::m_TrueNegativeValue
double m_TrueNegativeValue
Definition: otbConfusionMatrixCalculator.h:163
otb::ConfusionMatrixCalculator::ConfusionMatrixType
itk::VariableSizeMatrix< unsigned long > ConfusionMatrixType
Definition: otbConfusionMatrixCalculator.h:85
otb::ConfusionMatrixCalculator::m_FScore
double m_FScore
Definition: otbConfusionMatrixCalculator.h:169
otb::ConfusionMatrixCalculator::MeasurementType
itk::VariableLengthVector< double > MeasurementType
Definition: otbConfusionMatrixCalculator.h:91
otb::ConfusionMatrixCalculator::m_FScores
MeasurementType m_FScores
Definition: otbConfusionMatrixCalculator.h:160
otb::ConfusionMatrixCalculator::Self
ConfusionMatrixCalculator Self
Definition: otbConfusionMatrixCalculator.h:62
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ConfusionMatrixCalculator::m_FalseNegativeValue
double m_FalseNegativeValue
Definition: otbConfusionMatrixCalculator.h:162
otb::ConfusionMatrixCalculator::GetMapOfClasses
MapOfClassesType GetMapOfClasses() const
Definition: otbConfusionMatrixCalculator.h:125
otb::ConfusionMatrixCalculator::MapOfIndicesType
std::map< int, ClassLabelType > MapOfIndicesType
Definition: otbConfusionMatrixCalculator.h:82
otb::ConfusionMatrixCalculator::m_FalseNegativeValues
MeasurementType m_FalseNegativeValues
Definition: otbConfusionMatrixCalculator.h:153
otb::ConfusionMatrixCalculator::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbConfusionMatrixCalculator.h:64
otbMacro.h
otbConfusionMatrixMeasurements.h
otb::ConfusionMatrixCalculator::m_ProducedLabels
ProdListLabelPointerType m_ProducedLabels
Definition: otbConfusionMatrixCalculator.h:181
otb::ConfusionMatrixCalculator::m_NumberOfClasses
unsigned short m_NumberOfClasses
Definition: otbConfusionMatrixCalculator.h:174
otb::ConfusionMatrixCalculator::m_TruePositiveValues
MeasurementType m_TruePositiveValues
Definition: otbConfusionMatrixCalculator.h:156
otb::ConfusionMatrixCalculator::m_Precisions
MeasurementType m_Precisions
Definition: otbConfusionMatrixCalculator.h:158
otb::ConfusionMatrixCalculator::m_MapOfIndices
MapOfIndicesType m_MapOfIndices
Definition: otbConfusionMatrixCalculator.h:172
otb::ConfusionMatrixCalculator::MapOfClassesType
std::map< ClassLabelType, int > MapOfClassesType
Definition: otbConfusionMatrixCalculator.h:81
otb::ConfusionMatrixMeasurements
Definition: otbConfusionMatrixMeasurements.h:53
otb::ConfusionMatrixCalculator::m_ReferenceLabels
RefListLabelPointerType m_ReferenceLabels
Definition: otbConfusionMatrixCalculator.h:180
otb::ConfusionMatrixCalculator::m_MapOfClasses
MapOfClassesType m_MapOfClasses
Definition: otbConfusionMatrixCalculator.h:171
otb::ConfusionMatrixCalculator::m_Recall
double m_Recall
Definition: otbConfusionMatrixCalculator.h:168
otb::ConfusionMatrixCalculator::Superclass
itk::Object Superclass
Definition: otbConfusionMatrixCalculator.h:63
otb::ConfusionMatrixCalculator::RefListLabelType
TRefListLabel RefListLabelType
Definition: otbConfusionMatrixCalculator.h:71
otb::ConfusionMatrixCalculator::m_TrueNegativeValues
MeasurementType m_TrueNegativeValues
Definition: otbConfusionMatrixCalculator.h:154
otb::ConfusionMatrixCalculator::m_FalsePositiveValue
double m_FalsePositiveValue
Definition: otbConfusionMatrixCalculator.h:164
otb::ConfusionMatrixCalculator::m_Recalls
MeasurementType m_Recalls
Definition: otbConfusionMatrixCalculator.h:159
otb::ConfusionMatrixCalculator::m_ConfusionMatrix
ConfusionMatrixType m_ConfusionMatrix
Definition: otbConfusionMatrixCalculator.h:177
otb::ConfusionMatrixCalculator::GetMapOfIndices
MapOfIndicesType GetMapOfIndices() const
Definition: otbConfusionMatrixCalculator.h:133
otb::ConfusionMatrixCalculator::~ConfusionMatrixCalculator
~ConfusionMatrixCalculator() override
Definition: otbConfusionMatrixCalculator.h:140
otb::ConfusionMatrixCalculator::m_NumberOfSamples
unsigned long m_NumberOfSamples
Definition: otbConfusionMatrixCalculator.h:175
otb::ConfusionMatrixCalculator::ProdListLabelType
TProdListLabel ProdListLabelType
Definition: otbConfusionMatrixCalculator.h:77
otb::ConfusionMatrixCalculator::m_TruePositiveValue
double m_TruePositiveValue
Definition: otbConfusionMatrixCalculator.h:165
otb::ConfusionMatrixCalculator::m_Precision
double m_Precision
Definition: otbConfusionMatrixCalculator.h:167
otb::ConfusionMatrixCalculator::ClassLabelType
RefListLabelType::ValueType::ValueType ClassLabelType
Definition: otbConfusionMatrixCalculator.h:80
otb::ConfusionMatrixCalculator::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbConfusionMatrixCalculator.h:65
otb::ConfusionMatrixCalculator::ProdListLabelPointerType
ProdListLabelType::Pointer ProdListLabelPointerType
Definition: otbConfusionMatrixCalculator.h:78
otb::ConfusionMatrixMeasurements::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbConfusionMatrixMeasurements.h:59
otb::ConfusionMatrixCalculator::m_OverallAccuracy
double m_OverallAccuracy
Definition: otbConfusionMatrixCalculator.h:151
otb::ConfusionMatrixCalculator::RefListLabelPointerType
RefListLabelType::Pointer RefListLabelPointerType
Definition: otbConfusionMatrixCalculator.h:75
otb::ConfusionMatrixCalculator::m_ConfMatMeasurements
ConfusionMatrixMeasurementsType::Pointer m_ConfMatMeasurements
Definition: otbConfusionMatrixCalculator.h:178
otb::ConfusionMatrixCalculator
Definition: otbConfusionMatrixCalculator.h:58
otb::ConfusionMatrixCalculator::m_FalsePositiveValues
MeasurementType m_FalsePositiveValues
Definition: otbConfusionMatrixCalculator.h:155
otbConfusionMatrixCalculator.hxx