OTB  9.0.0
Orfeo Toolbox
otbISRAUnmixingImageFilter.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 otbISRAUnmixingImageFilter_hxx
22 #define otbISRAUnmixingImageFilter_hxx
23 
25 #include <algorithm>
26 
27 namespace otb
28 {
29 
30 namespace Functor
31 {
32 
33 template <class TInput, class TOutput, class TPrecision>
35 {
36 }
37 
38 template <class TInput, class TOutput, class TPrecision>
39 size_t ISRAUnmixingFunctor<TInput, TOutput, TPrecision>::OutputSize(const std::array<size_t, 1>&) const
40 {
41  return m_OutputSize;
42 }
43 
44 template <class TInput, class TOutput, class TPrecision>
46 {
47  m_U = U;
48  m_OutputSize = m_U.cols();
49  m_Svd.reset(new SVDType(m_U));
50 }
51 
52 
53 template <class TInput, class TOutput, class TPrecision>
55 {
56  return m_U;
57 }
58 
59 template <class TInput, class TOutput, class TPrecision>
61 {
62  // TODO : support different types between input and output ?
63  VectorType inVector(in.Size());
64  for (unsigned int i = 0; i < in.GetSize(); ++i)
65  {
66  inVector[i] = in[i];
67  }
68 
69  // Initialize with Unconstrained Least Square solution
70  VectorType outVector = m_Svd->solve(inVector);
71 
72  unsigned int nbEndmembers = m_OutputSize;
73  unsigned int nbBands = in.Size();
74 
75  // Apply ISRA iterations
76  for (unsigned int i = 0; i < m_MaxIteration; ++i)
77  {
78 
79  // Use a temporary storage since it is used
80  // inside the iterations
81  VectorType outVectorNew = outVector;
82  for (unsigned int e = 0; e < nbEndmembers; ++e)
83  {
84  PrecisionType numerator = 0;
85  PrecisionType denominator = 0;
86 
87  for (unsigned int b = 0; b < nbBands; ++b)
88  {
89  numerator += in[b] * m_U(b, e);
90 
91  PrecisionType dot = 0;
92  for (unsigned int s = 0; s < nbEndmembers; ++s)
93  {
94  // Use outVector from previous iteration here
95  dot += m_U(b, s) * outVector[s];
96  }
97  denominator += dot * m_U(b, e);
98  }
99 
100  outVectorNew[e] *= (numerator / denominator);
101  }
102 
103  // Prepare for next iteration
104  outVector = outVectorNew;
105  }
106 
107  OutputType out(outVector.size());
108  for (unsigned int i = 0; i < out.GetSize(); ++i)
109  {
110  out[i] = outVector[i];
111  }
112  return out;
113 }
114 
115 } // end namespace functor
116 } // end namespace otb
117 
118 #endif
otb::Functor::ISRAUnmixingFunctor::SVDType
vnl_svd< PrecisionType > SVDType
Definition: otbISRAUnmixingImageFilter.h:82
otb::Functor::ISRAUnmixingFunctor::SetEndmembersMatrix
void SetEndmembersMatrix(const MatrixType &U)
Definition: otbISRAUnmixingImageFilter.hxx:45
otb::Functor::ISRAUnmixingFunctor::VectorType
vnl_vector< PrecisionType > VectorType
Definition: otbISRAUnmixingImageFilter.h:53
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::ISRAUnmixingFunctor::OutputType
TOutput OutputType
Definition: otbISRAUnmixingImageFilter.h:50
otb::Functor::ISRAUnmixingFunctor::GetEndmembersMatrix
const MatrixType & GetEndmembersMatrix(void) const
Definition: otbISRAUnmixingImageFilter.hxx:54
otb::Functor::ISRAUnmixingFunctor::InputType
TInput InputType
Definition: otbISRAUnmixingImageFilter.h:49
otb::Functor::ISRAUnmixingFunctor::PrecisionType
TPrecision PrecisionType
Definition: otbISRAUnmixingImageFilter.h:51
otb::Functor::ISRAUnmixingFunctor::operator()
OutputType operator()(const InputType &in) const
Definition: otbISRAUnmixingImageFilter.hxx:60
otb::Functor::ISRAUnmixingFunctor::OutputSize
vcl_size_t OutputSize(const std::array< vcl_size_t, 1 > &nbBands) const
Definition: otbISRAUnmixingImageFilter.hxx:39
otb::Functor::ISRAUnmixingFunctor::MatrixType
vnl_matrix< PrecisionType > MatrixType
Definition: otbISRAUnmixingImageFilter.h:54
otbISRAUnmixingImageFilter.h
otb::Functor::ISRAUnmixingFunctor::ISRAUnmixingFunctor
ISRAUnmixingFunctor()
Definition: otbISRAUnmixingImageFilter.hxx:34