OTB  10.0.0
Orfeo Toolbox
otbConfusionMatrixMeasurements.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 
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:
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
itk::VariableLengthVector< double > MeasurementType
std::map< ClassLabelType, int > MapOfClassesType
ConfusionMatrixMeasurements(const Self &)=delete
virtual void SetMapOfIndices(const MapOfIndicesType &_arg)
void operator=(const Self &)=delete
virtual void SetMapOfClasses(const MapOfClassesType &_arg)
itk::SmartPointer< const Self > ConstPointer
std::map< int, ClassLabelType > MapOfIndicesType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.