OTB  9.0.0
Orfeo Toolbox
otbVirtualDimensionality.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbVirtualDimensionality_hxx
23 #define otbVirtualDimensionality_hxx
24 
26 
27 #include <algorithm>
29 
30 namespace otb
31 {
32 
33 template <class TPrecision>
34 VirtualDimensionality<TPrecision>::VirtualDimensionality() : m_NumberOfPixels(0), m_NumberOfEndmembers(0), m_FAR(1.0E-3)
35 {
36 }
37 
38 template <class TInputImage>
40 {
41  // TODO check size
42  const unsigned int nbBands = m_Covariance.rows();
43 
44  // Compute diagonalisation of sample covariance and correlation matrices
45  vnl_symmetric_eigensystem<PrecisionType> eigenK(m_Covariance);
46  VectorType eigenCovariance = eigenK.D.diagonal();
47  std::sort(eigenCovariance.begin(), eigenCovariance.end());
48  eigenCovariance.flip();
49 
50  vnl_symmetric_eigensystem<PrecisionType> eigenR(m_Correlation);
51  VectorType eigenCorrelation = eigenR.D.diagonal();
52  std::sort(eigenCorrelation.begin(), eigenCorrelation.end());
53  eigenCorrelation.flip();
54 
55  m_NumberOfEndmembers = 0;
56  for (unsigned int i = 0; i < nbBands; ++i)
57  {
58  if (eigenCovariance[i] > 0 && eigenCorrelation[i] > 0)
59  {
60  double sigma = std::sqrt(2.0 / m_NumberOfPixels * (eigenCovariance[i] * eigenCovariance[i] + eigenCorrelation[i] * eigenCorrelation[i]));
61  boost::math::normal normalDist(0, sigma);
62  double tau = -boost::math::quantile(normalDist, m_FAR);
63  if (eigenCorrelation[i] - eigenCovariance[i] > tau)
64  m_NumberOfEndmembers++;
65  }
66  }
67 }
68 
69 template <class TImage>
70 void VirtualDimensionality<TImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
71 {
72  Superclass::PrintSelf(os, indent);
73 
74  os << indent << "Covariance: " << m_Covariance << std::endl;
75  os << indent << "Correlation: " << m_Correlation << std::endl;
76  os << indent << "NumberOfEndmembers: " << m_NumberOfEndmembers << std::endl;
77 }
78 
79 } // end namespace otb
80 #endif
otbVirtualDimensionality.h
otb_boost_math_normal_header.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VirtualDimensionality::VectorType
vnl_vector< PrecisionType > VectorType
Definition: otbVirtualDimensionality.h:77
otb::VirtualDimensionality::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbVirtualDimensionality.hxx:70
otb::VirtualDimensionality::VirtualDimensionality
VirtualDimensionality()
Definition: otbVirtualDimensionality.hxx:34
otb::VirtualDimensionality::Compute
void Compute()
Definition: otbVirtualDimensionality.hxx:39