OTB  9.0.0
Orfeo Toolbox
otbLineCorrelationDetectorImageFilter.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 otbLineCorrelationDetectorImageFilter_hxx
22 #define otbLineCorrelationDetectorImageFilter_hxx
23 
25 
26 #include "itkDataObject.h"
27 #include "itkConstNeighborhoodIterator.h"
28 #include "itkNeighborhoodInnerProduct.h"
29 #include "itkImageRegionIterator.h"
30 #include "itkNeighborhoodAlgorithm.h"
31 #include "itkProgressReporter.h"
32 #include "otbMath.h"
33 
34 namespace otb
35 {
36 
40 template <class TInputImage, class TOutputImage, class TOutputImageDirection, class TInterpolator>
42 {
43  this->m_Radius.Fill(1);
44  this->m_LengthLine = 1;
45  this->m_WidthLine = 0;
46  this->m_FaceList.Fill(0);
47 }
49 
50 template <class TInputImage, class TOutputImage, class TOutputImageDirection, class TInterpolator>
52  std::vector<double>* m2,
53  std::vector<double>* m3)
54 {
55 
56  double M1 = 0.0;
57  double M2 = 0.0;
58  double M3 = 0.0;
59 
60  std::vector<double>::iterator m1It = m1->begin();
61  std::vector<double>::iterator m1End = m1->end();
62 
63  std::vector<double>::iterator m2It = m2->begin();
64  std::vector<double>::iterator m2End = m2->end();
65 
66  std::vector<double>::iterator m3It = m3->begin();
67  std::vector<double>::iterator m3End = m3->end();
68 
69  while (m1It != m1End && m2It != m2End && m3It != m3End)
70  {
71 
72  M1 += (*m1It);
73  ++m1It;
74 
75  M2 += (*m2It);
76  ++m2It;
77 
78  M3 += (*m3It);
79  ++m3It;
80  }
81 
82  M1 /= m1->size();
83  M2 /= m2->size();
84  M3 /= m3->size();
85 
86  double sigma1 = 0.0;
87  double sigma2 = 0.0;
88  double sigma3 = 0.0;
89 
90  m1It = m1->begin();
91  m2It = m2->begin();
92  m3It = m3->begin();
93 
94  while (m1It != m1End && m2It != m2End && m3It != m3End)
95  {
96 
97  sigma1 += std::pow((*m1It) - M1, 2);
98  ++m1It;
99 
100  sigma2 += std::pow((*m2It) - M2, 2);
101  ++m2It;
102 
103  sigma3 += std::pow((*m3It) - M3, 2);
104  ++m3It;
105  }
106 
107  sigma1 /= m1->size();
108  sigma2 /= m2->size();
109  sigma3 /= m3->size();
110 
111  // Actually, we use the variance
112  /* sigma1 = std::sqrt(sigma1);
113  sigma2 = std::sqrt(sigma2);
114  sigma3 = std::sqrt(sigma3);
115  */
116 
117  // Calculation of the cross correlation coefficient
118 
119  double d1 = 0.;
120  double d2 = 0.;
121  double d3 = 0.;
122 
123  double rho12 = 0.;
124  double rho13 = 0.;
125 
126  // rho12
127  if (M2 != 0.)
128  {
129  d1 = sigma1 / std::pow(M2, 2) * m1->size();
130  d2 = sigma2 / std::pow(M2, 2) * m2->size();
131 
132  d3 = std::pow(((M1 / M2) - 1.), 2) * (m1->size() * m2->size());
133 
134  if ((d3 != 0.))
135  rho12 = static_cast<double>(1. / (1. + ((m1->size() + m2->size()) * (d1 + d2) / d3)));
136  else
137  rho12 = 0.;
138  }
139  if (M3 != 0.)
140  {
141  d1 = sigma1 / std::pow(M3, 2) * m1->size();
142  d2 = sigma3 / std::pow(M3, 2) * m2->size();
143 
144  d3 = std::pow(((M1 / M3) - 1.), 2) * (m1->size() * m2->size());
145 
146  if ((d3 != 0.))
147  rho13 = static_cast<double>(1. / (1. + ((m1->size() + m2->size()) * (d1 + d2) / d3)));
148  else
149  rho13 = 0.;
150  }
151 
152  rho12 = std::sqrt(rho12);
153  rho13 = std::sqrt(rho13);
154 
155  // Determination of the minimum intensity of detection between R12 et R13
156  return static_cast<double>(std::min(rho12, rho13));
157 }
158 
162 template <class TInputImage, class TOutputImage, class TOutputImageDirection, class TInterpolator>
164 {
165  Superclass::PrintSelf(os, indent);
166 }
167 
168 } // end namespace otb
169 
170 #endif
otb::LineCorrelationDetectorImageFilter::LineCorrelationDetectorImageFilter
LineCorrelationDetectorImageFilter()
Definition: otbLineCorrelationDetectorImageFilter.hxx:41
otb::LineCorrelationDetectorImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbLineCorrelationDetectorImageFilter.hxx:163
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::LineCorrelationDetectorImageFilter::ComputeMeasure
double ComputeMeasure(std::vector< double > *m1, std::vector< double > *m2, std::vector< double > *m3) override
Definition: otbLineCorrelationDetectorImageFilter.hxx:51
otbLineCorrelationDetectorImageFilter.h