OTB  9.0.0
Orfeo Toolbox
otbHooverMatrixFilter.hxx
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 otbHooverMatrixFilter_hxx
22 #define otbHooverMatrixFilter_hxx
23 
24 #include "otbHooverMatrixFilter.h"
25 
26 namespace otb
27 {
28 
30 template <class TLabelMap>
31 HooverMatrixFilter<TLabelMap>::HooverMatrixFilter() : m_NumberOfRegionsGT(0), m_NumberOfRegionsMS(0)
32 {
33  this->SetNumberOfRequiredInputs(2);
34  m_Matrix.SetSize(0, 0);
35 }
37 
39 template <class TLabelMap>
41 {
42  this->SetInput(0, gt);
43 }
44 
46 template <class TLabelMap>
48 {
49  this->SetInput(1, ms);
50 }
51 
53 template <class TLabelMap>
55 {
56  return this->GetInput(0);
57 }
58 
60 template <class TLabelMap>
62 {
63  return this->GetInput(1);
64 }
65 
66 template <class TLabelMap>
68 {
69  // first : call superclass method
70  Superclass::BeforeThreadedGenerateData();
71 
72  // Set the matrix size
73  m_NumberOfRegionsGT = this->GetGroundTruthLabelMap()->GetNumberOfLabelObjects();
74  m_NumberOfRegionsMS = this->GetMachineSegmentationLabelMap()->GetNumberOfLabelObjects();
75  m_LabelsGT = this->GetGroundTruthLabelMap()->GetLabels();
76  m_Matrix.SetSize(m_NumberOfRegionsGT, m_NumberOfRegionsMS);
77  m_Matrix.Fill(0);
78 }
79 
80 template <class TLabelMap>
82 {
83 
84 
85  unsigned long currentRegionMS = 0;
86  unsigned long currentRegionGT = 0;
87  // find the index of the current GT region
88  LabelType currentLabelGT = labelObject->GetLabel();
89  for (unsigned long k = 0; k < m_NumberOfRegionsGT; k++)
90  {
91  if (currentLabelGT == m_LabelsGT[k])
92  {
93  currentRegionGT = k;
94  break;
95  }
96  }
97 
98  // loop over the given region
99  typedef typename LabelObjectType::ConstLineIterator IteratorType;
100  IteratorType lit = IteratorType(labelObject);
101  while (!lit.IsAtEnd())
102  {
103  IndexType idx = lit.GetLine().GetIndex();
104  unsigned long length = lit.GetLine().GetLength();
105  for (unsigned long i = 0; i < length; i++)
106  {
107  // find the corresponding label in the ms label map
108  // if found : ++ in the cell [n, p]
109  for (unsigned long j = currentRegionMS; j < (currentRegionMS + m_NumberOfRegionsMS); j++)
110  {
111  // TODO : optimize here : call GetLabelObject(label) would be faster
112  const LabelObjectType* regionMS = this->GetMachineSegmentationLabelMap()->GetNthLabelObject(j % m_NumberOfRegionsMS);
113  if (regionMS->HasIndex(idx))
114  {
115  currentRegionMS = j % m_NumberOfRegionsMS;
116  m_Matrix(currentRegionGT, currentRegionMS)++;
117  break;
118  }
119  }
120  idx[0]++;
121  }
122  ++lit;
123  }
124 }
125 }
126 #endif
otb::HooverMatrixFilter::HooverMatrixFilter
HooverMatrixFilter()
Definition: otbHooverMatrixFilter.hxx:31
otb::HooverMatrixFilter::ThreadedProcessLabelObject
void ThreadedProcessLabelObject(LabelObjectType *labelObject) override
Definition: otbHooverMatrixFilter.hxx:81
otb::HooverMatrixFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: otbHooverMatrixFilter.hxx:67
otb::HooverMatrixFilter::LabelType
LabelObjectType::LabelType LabelType
Definition: otbHooverMatrixFilter.h:65
otb::HooverMatrixFilter::SetMachineSegmentationLabelMap
void SetMachineSegmentationLabelMap(const LabelMapType *ms)
Definition: otbHooverMatrixFilter.hxx:47
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::HooverMatrixFilter::LabelObjectType
LabelMapType::LabelObjectType LabelObjectType
Definition: otbHooverMatrixFilter.h:60
otb::HooverMatrixFilter::IndexType
LabelObjectType::IndexType IndexType
Definition: otbHooverMatrixFilter.h:64
otb::HooverMatrixFilter::SetGroundTruthLabelMap
void SetGroundTruthLabelMap(const LabelMapType *gt)
Definition: otbHooverMatrixFilter.hxx:40
otb::HooverMatrixFilter::GetMachineSegmentationLabelMap
const LabelMapType * GetMachineSegmentationLabelMap()
Definition: otbHooverMatrixFilter.hxx:61
otb::HooverMatrixFilter::m_Matrix
MatrixType m_Matrix
Definition: otbHooverMatrixFilter.h:114
otbHooverMatrixFilter.h
otb::HooverMatrixFilter::GetGroundTruthLabelMap
const LabelMapType * GetGroundTruthLabelMap()
Definition: otbHooverMatrixFilter.hxx:54
otb::HooverMatrixFilter::LabelMapType
TLabelMap LabelMapType
Definition: otbHooverMatrixFilter.h:56