OTB  9.0.0
Orfeo Toolbox
otbConfusionMatrixMeasurements.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 otbConfusionMatrixMeasurements_h
23 #define otbConfusionMatrixMeasurements_h
24 
25 #include "itkObject.h"
26 #include "itkObjectFactory.h"
27 #include "itkVariableSizeMatrix.h"
28 #include "itkVariableLengthVector.h"
29 
30 namespace otb
31 {
52 template <class TConfusionMatrix = itk::VariableSizeMatrix<unsigned long>, class TLabel = int>
53 class ITK_EXPORT ConfusionMatrixMeasurements : public itk::Object
54 {
55 public:
58  typedef itk::Object Superclass;
59  typedef itk::SmartPointer<Self> Pointer;
60  typedef itk::SmartPointer<const Self> ConstPointer;
61 
63  itkTypeMacro(ConfusionMatrixMeasurements, itk::Object);
64 
66  itkNewMacro(Self);
67 
68  typedef TLabel ClassLabelType;
69  typedef std::map<ClassLabelType, int> MapOfClassesType;
70  typedef std::map<int, ClassLabelType> MapOfIndicesType;
71 
73  typedef TConfusionMatrix ConfusionMatrixType;
74 
76  typedef itk::VariableLengthVector<double> MeasurementType;
77 
78 
80  void Compute(void);
81 
83  itkSetMacro(ConfusionMatrix, ConfusionMatrixType);
84 
85  itkGetMacro(TruePositiveValues, MeasurementType);
86  itkGetMacro(TrueNegativeValues, MeasurementType);
87  itkGetMacro(FalsePositiveValues, MeasurementType);
88  itkGetMacro(FalseNegativeValues, MeasurementType);
89  itkGetMacro(TruePositiveValue, double);
90  itkGetMacro(TrueNegativeValue, double);
91  itkGetMacro(FalsePositiveValue, double);
92  itkGetMacro(FalseNegativeValue, double);
93  itkGetMacro(KappaIndex, double);
94  itkGetMacro(OverallAccuracy, double);
95  itkGetMacro(Precisions, MeasurementType);
96  itkGetMacro(Recalls, MeasurementType);
97  itkGetMacro(FScores, MeasurementType);
98  itkGetMacro(Precision, double);
99  itkGetMacro(Recall, double);
100  itkGetMacro(FScore, double);
101  itkGetMacro(NumberOfClasses, unsigned short);
102  itkGetMacro(NumberOfSamples, unsigned long);
103 
104  /* Gives the correspondence between a class label
105  * and its index in the confusion matrix
106  */
107  virtual void SetMapOfClasses(const MapOfClassesType &_arg)
108  {
109  m_MapOfClasses = _arg;
110  typename MapOfClassesType::iterator itMapOfClasses;
111  m_MapOfIndices.clear();
112  for (itMapOfClasses = m_MapOfClasses.begin(); itMapOfClasses != m_MapOfClasses.end(); ++itMapOfClasses)
113  {
114  m_MapOfIndices[itMapOfClasses->second] = itMapOfClasses->first;
115  }
116  }
117 
119  {
120  return m_MapOfClasses;
121  }
122 
123 
124  /* Gives the correspondence between an index in the
125  * confusion matrix and the class label
126  */
127  virtual void SetMapOfIndices(const MapOfIndicesType &_arg)
128  {
129  m_MapOfIndices = _arg;
130  typename MapOfIndicesType::iterator itMapOfIndices;
131  m_MapOfClasses.clear();
132  for (itMapOfIndices = m_MapOfIndices.begin(); itMapOfIndices != m_MapOfIndices.end(); ++itMapOfIndices)
133  {
134  m_MapOfClasses[itMapOfIndices->second] = itMapOfIndices->first;
135  }
136  }
137 
139  {
140  return m_MapOfIndices;
141  }
142 
143 protected:
146  {
147  }
148  // void PrintSelf(std::ostream& os, itk::Indent indent) const;
149 
150 
151 private:
152  ConfusionMatrixMeasurements(const Self&) = delete;
153  void operator=(const Self&) = delete;
154 
155  double m_KappaIndex;
157 
162 
166 
171 
172  double m_Precision;
173  double m_Recall;
174  double m_FScore;
175 
178 
179  unsigned short m_NumberOfClasses;
180  unsigned long m_NumberOfSamples;
181 
183 };
184 } // end of namespace otb
185 
186 #ifndef OTB_MANUAL_INSTANTIATION
188 #endif
189 
190 #endif
otb::ConfusionMatrixMeasurements::m_TruePositiveValue
double m_TruePositiveValue
Definition: otbConfusionMatrixMeasurements.h:170
otb::ConfusionMatrixMeasurements::SetMapOfClasses
virtual void SetMapOfClasses(const MapOfClassesType &_arg)
Definition: otbConfusionMatrixMeasurements.h:107
otb::ConfusionMatrixMeasurements::m_FScore
double m_FScore
Definition: otbConfusionMatrixMeasurements.h:174
otb::ConfusionMatrixMeasurements::Self
ConfusionMatrixMeasurements Self
Definition: otbConfusionMatrixMeasurements.h:57
otb::ConfusionMatrixMeasurements::m_TrueNegativeValue
double m_TrueNegativeValue
Definition: otbConfusionMatrixMeasurements.h:168
otb::ConfusionMatrixMeasurements::m_MapOfIndices
MapOfIndicesType m_MapOfIndices
Definition: otbConfusionMatrixMeasurements.h:177
otb::ConfusionMatrixMeasurements::m_KappaIndex
double m_KappaIndex
Definition: otbConfusionMatrixMeasurements.h:155
otb::ConfusionMatrixMeasurements::m_FScores
MeasurementType m_FScores
Definition: otbConfusionMatrixMeasurements.h:165
otb::ConfusionMatrixMeasurements::MeasurementType
itk::VariableLengthVector< double > MeasurementType
Definition: otbConfusionMatrixMeasurements.h:76
otb::ConfusionMatrixMeasurements::MapOfIndicesType
std::map< int, ClassLabelType > MapOfIndicesType
Definition: otbConfusionMatrixMeasurements.h:70
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbConfusionMatrixMeasurements.hxx
otb::ConfusionMatrixMeasurements::m_OverallAccuracy
double m_OverallAccuracy
Definition: otbConfusionMatrixMeasurements.h:156
otb::ConfusionMatrixMeasurements::m_FalseNegativeValue
double m_FalseNegativeValue
Definition: otbConfusionMatrixMeasurements.h:167
otb::ConfusionMatrixMeasurements::m_Recall
double m_Recall
Definition: otbConfusionMatrixMeasurements.h:173
otb::ConfusionMatrixMeasurements::m_Recalls
MeasurementType m_Recalls
Definition: otbConfusionMatrixMeasurements.h:164
otb::ConfusionMatrixMeasurements::m_FalsePositiveValue
double m_FalsePositiveValue
Definition: otbConfusionMatrixMeasurements.h:169
otb::ConfusionMatrixMeasurements::SetMapOfIndices
virtual void SetMapOfIndices(const MapOfIndicesType &_arg)
Definition: otbConfusionMatrixMeasurements.h:127
otb::ConfusionMatrixMeasurements::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbConfusionMatrixMeasurements.h:60
otb::ConfusionMatrixMeasurements
Definition: otbConfusionMatrixMeasurements.h:53
otb::ConfusionMatrixMeasurements::m_FalseNegativeValues
MeasurementType m_FalseNegativeValues
Definition: otbConfusionMatrixMeasurements.h:158
otb::ConfusionMatrixMeasurements::m_Precision
double m_Precision
Definition: otbConfusionMatrixMeasurements.h:172
otb::ConfusionMatrixMeasurements::Superclass
itk::Object Superclass
Definition: otbConfusionMatrixMeasurements.h:58
otb::ConfusionMatrixMeasurements::MapOfClassesType
std::map< ClassLabelType, int > MapOfClassesType
Definition: otbConfusionMatrixMeasurements.h:69
otb::ConfusionMatrixMeasurements::ConfusionMatrixType
TConfusionMatrix ConfusionMatrixType
Definition: otbConfusionMatrixMeasurements.h:73
otb::ConfusionMatrixMeasurements::~ConfusionMatrixMeasurements
~ConfusionMatrixMeasurements() override
Definition: otbConfusionMatrixMeasurements.h:145
otb::ConfusionMatrixMeasurements::m_FalsePositiveValues
MeasurementType m_FalsePositiveValues
Definition: otbConfusionMatrixMeasurements.h:160
otb::ConfusionMatrixMeasurements::m_ConfusionMatrix
ConfusionMatrixType m_ConfusionMatrix
Definition: otbConfusionMatrixMeasurements.h:182
otb::ConfusionMatrixMeasurements::m_TruePositiveValues
MeasurementType m_TruePositiveValues
Definition: otbConfusionMatrixMeasurements.h:161
otb::ConfusionMatrixMeasurements::m_NumberOfClasses
unsigned short m_NumberOfClasses
Definition: otbConfusionMatrixMeasurements.h:179
otb::ConfusionMatrixMeasurements::m_Precisions
MeasurementType m_Precisions
Definition: otbConfusionMatrixMeasurements.h:163
otb::ConfusionMatrixMeasurements::m_MapOfClasses
MapOfClassesType m_MapOfClasses
Definition: otbConfusionMatrixMeasurements.h:176
otb::ConfusionMatrixMeasurements::m_NumberOfSamples
unsigned long m_NumberOfSamples
Definition: otbConfusionMatrixMeasurements.h:180
otb::ConfusionMatrixMeasurements::GetMapOfClasses
MapOfClassesType GetMapOfClasses() const
Definition: otbConfusionMatrixMeasurements.h:118
otb::ConfusionMatrixMeasurements::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbConfusionMatrixMeasurements.h:59
otb::ConfusionMatrixMeasurements::GetMapOfIndices
MapOfIndicesType GetMapOfIndices() const
Definition: otbConfusionMatrixMeasurements.h:138
otb::ConfusionMatrixMeasurements::m_TrueNegativeValues
MeasurementType m_TrueNegativeValues
Definition: otbConfusionMatrixMeasurements.h:159
otb::ConfusionMatrixMeasurements::ClassLabelType
TLabel ClassLabelType
Definition: otbConfusionMatrixMeasurements.h:66