Orfeo ToolBox  4.2
Orfeo ToolBox is not a black box
otbISRAUnmixingImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbISRAUnmixingImageFilter_txx
19 #define __otbISRAUnmixingImageFilter_txx
20 
22 #include <algorithm>
23 
24 namespace otb
25 {
26 
27 namespace Functor
28 {
29 
30 template <class TInput, class TOutput, class TPrecision>
33  : m_OutputSize(0),
34  m_MaxIteration(100)
35 {
36 }
37 
38 template <class TInput, class TOutput, class TPrecision>
41 {
42 }
43 
44 template <class TInput, class TOutput, class TPrecision>
45 unsigned int
48 {
49  return m_OutputSize;
50 }
51 
52 template <class TInput, class TOutput, class TPrecision>
53 bool
55 ::operator != (const Self& other) const
56 {
57  return true;
58 }
59 
60 template <class TInput, class TOutput, class TPrecision>
61 bool
63 ::operator == (const Self& other) const
64 {
65  return false;
66 }
67 
68 template <class TInput, class TOutput, class TPrecision>
69 void
72 {
73  m_U = U;
74  m_OutputSize = m_U.cols();
75  m_Svd.reset( new SVDType(m_U) );
76 }
77 
78 
79 template <class TInput, class TOutput, class TPrecision>
83 {
84  return m_U;
85 }
86 
87 template <class TInput, class TOutput, class TPrecision>
90 ::operator ()(const InputType& in) const
91 {
92  // TODO : support different types between input and output ?
93  VectorType inVector(in.Size());
94  for (unsigned int i = 0; i < in.GetSize(); ++i )
95  {
96  inVector[i] = in[i];
97  }
98 
99  // Initialize with Unconstrained Least Square solution
100  VectorType outVector = m_Svd->solve(inVector);
101 
102  unsigned int nbEndmembers = m_OutputSize;
103  unsigned int nbBands = in.Size();
104 
105  // Apply ISRA iterations
106  for (unsigned int i = 0; i < m_MaxIteration; ++i)
107  {
108 
109  // Use a temporary storage since it is used
110  // inside the iterations
111  VectorType outVectorNew = outVector;
112  for (unsigned int e = 0; e < nbEndmembers; ++e)
113  {
114  PrecisionType numerator = 0;
115  PrecisionType denominator = 0;
116 
117  for (unsigned int b = 0; b < nbBands; ++b)
118  {
119  numerator += in[b] * m_U(b, e);
120 
121  PrecisionType dot = 0;
122  for (unsigned int s = 0; s < nbEndmembers; ++s)
123  {
124  // Use outVector from previous iteration here
125  dot += m_U(b, s) * outVector[s];
126  }
127  denominator += dot * m_U(b, e);
128  }
129 
130  outVectorNew[e] *= (numerator/denominator);
131  }
132 
133  // Prepare for next iteration
134  outVector = outVectorNew;
135  }
136 
137  OutputType out(outVector.size());
138  for (unsigned int i = 0; i < out.GetSize(); ++i )
139  {
140  out[i] = outVector[i];
141  }
142  return out;
143 }
144 
145 }
146 
147 template <class TInputImage, class TOutputImage, class TPrecision>
150 {
151 }
152 
153 template <class TInputImage, class TOutputImage, class TPrecision>
156 {
157 }
158 
159 template <class TInputImage, class TOutputImage, class TPrecision>
160 void
163 {
164  this->GetFunctor().SetEndmembersMatrix(m);
165  this->Modified();
166 }
167 
168 template <class TInputImage, class TOutputImage, class TPrecision>
172 {
173  return this->GetFunctor().GetEndmembersMatrix();
174 }
175 
176 template <class TInputImage, class TOutputImage, class TPrecision>
177 void
179 ::PrintSelf(std::ostream& os, itk::Indent indent) const
180 {
181  Superclass::PrintSelf(os, indent);
182 }
183 
184 } // end namespace
185 
186 #endif
void SetEndmembersMatrix(const MatrixType &m)
void PrintSelf(std::ostream &os, itk::Indent indent) const
bool operator==(const ISRAUnmixingFunctor &other) const
const MatrixType & GetEndmembersMatrix() const
OutputType operator()(const InputType &in) const
bool operator!=(const ISRAUnmixingFunctor &other) const
const MatrixType & GetEndmembersMatrix(void) const