OTB  9.0.0
Orfeo Toolbox
otbLineRatioDetectorImageFilter.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 otbLineRatioDetectorImageFilter_hxx
22 #define otbLineRatioDetectorImageFilter_hxx
23 
25 #include "otbMacro.h"
26 
27 #include "itkDataObject.h"
28 #include "itkConstNeighborhoodIterator.h"
29 #include "itkNeighborhoodInnerProduct.h"
30 #include "itkImageRegionIterator.h"
31 #include "itkNeighborhoodAlgorithm.h"
32 #include "itkProgressReporter.h"
33 #include "otbMath.h"
34 
35 namespace otb
36 {
37 
41 template <class TInputImage, class TOutputImage, class TOutputImageDirection, class TInterpolator>
43 {
44  this->m_Radius.Fill(1);
45  this->m_LengthLine = 1;
46  this->m_WidthLine = 0;
47  this->m_FaceList.Fill(0);
48 }
50 
51 template <class TInputImage, class TOutputImage, class TOutputImageDirection, class TInterpolator>
53  std::vector<double>* m2,
54  std::vector<double>* m3)
55 {
56 
57  double M1 = 0.0;
58  double M2 = 0.0;
59  double M3 = 0.0;
60 
61  std::vector<double>::iterator m1It = m1->begin();
62  std::vector<double>::iterator m1End = m1->end();
63 
64  std::vector<double>::iterator m2It = m2->begin();
65  std::vector<double>::iterator m2End = m2->end();
66 
67  std::vector<double>::iterator m3It = m3->begin();
68  std::vector<double>::iterator m3End = m3->end();
69 
70  while (m1It != m1End && m2It != m2End && m3It != m3End)
71  {
72 
73  M1 += (*m1It);
74  ++m1It;
75 
76  M2 += (*m2It);
77  ++m2It;
78 
79  M3 += (*m3It);
80  ++m3It;
81  }
82 
83  M1 /= m1->size();
84  M2 /= m2->size();
85  M3 /= m3->size();
86 
87  double R12 = 0.0;
88  double R13 = 0.0;
89 
90  double epsilon = 0.0000000001;
91  if ((std::abs(M1) > epsilon) && (std::abs(M2) > epsilon))
92  R12 = static_cast<double>(1 - std::min((M1 / M2), (M2 / M1)));
93  else if ((std::abs(M1) > epsilon) || (std::abs(M2) > epsilon))
94  R12 = 1.0;
95  else
96  R12 = 0.;
97 
98  if ((std::abs(M1) > epsilon) && (std::abs(M3) > epsilon))
99  R13 = static_cast<double>(1 - std::min((M1 / M3), (M3 / M1)));
100  else if ((std::abs(M1) > epsilon) || (std::abs(M3) > epsilon))
101  R13 = 1.0;
102  else
103  R13 = 0.;
104 
105  // Determination of the minimum intensity of detection between R12 et R13
106  return static_cast<double>(std::min(R12, R13));
107 }
108 
112 template <class TInputImage, class TOutputImage, class TOutputImageDirection, class TInterpolator>
114 {
115  Superclass::PrintSelf(os, indent);
116 }
117 
118 } // end namespace otb
119 
120 #endif
otb::LineRatioDetectorImageFilter::LineRatioDetectorImageFilter
LineRatioDetectorImageFilter()
Definition: otbLineRatioDetectorImageFilter.hxx:42
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::LineRatioDetectorImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbLineRatioDetectorImageFilter.hxx:113
otbLineRatioDetectorImageFilter.h
otb::LineRatioDetectorImageFilter::ComputeMeasure
double ComputeMeasure(std::vector< double > *m1, std::vector< double > *m2, std::vector< double > *m3) override
Definition: otbLineRatioDetectorImageFilter.hxx:52