OTB  9.0.0
Orfeo Toolbox
otbBayesianFusionFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Julien Radoux
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 otbBayesianFusionFilter_h
22 #define otbBayesianFusionFilter_h
23 
24 #include "itkImageToImageFilter.h"
25 #include "otbVectorImage.h"
27 #include "otbFunctorImageFilter.h"
30 
31 namespace otb
32 {
33 
34 namespace Functor
35 {
42 template <class TInputMultiSpectral, class TInputMultiSpectralInterp, class TInputPanchro, class TOutput>
44 {
45 public:
47  {
48  }
49  virtual ~BayesianFunctor()
50  {
51  }
52  typedef typename TInputMultiSpectral::RealValueType RealType;
53  typedef typename itk::VariableSizeMatrix<RealType> MatrixType;
54 
55  void SetLambda(float lambda)
56  {
57  m_Lambda = lambda;
58  }
59  void SetS(float S)
60  {
61  m_S = S;
62  }
63  void SetAlpha(float alpha)
64  {
65  m_Alpha = alpha;
66  }
67  void SetBeta(MatrixType matrix)
68  {
69  m_Beta = matrix;
70  }
72  {
73  m_CovarianceInvMatrix = matrix;
74  }
75  void SetVcondopt(MatrixType matrix)
76  {
77  m_Vcondopt = matrix;
78  }
79  float GetLambda()
80  {
81  return m_Lambda;
82  }
83  float GetAlpha()
84  {
85  return m_Alpha;
86  }
87  float GetS()
88  {
89  return m_S;
90  }
92  {
93  return m_Beta;
94  }
96  {
97  return m_CovarianceInvMatrix;
98  }
100  {
101  return m_Vcondopt;
102  }
103 
104  void operator()(TOutput& obs, const TInputMultiSpectral& itkNotUsed(ms), const TInputMultiSpectralInterp& msi, const TInputPanchro& p)
105  {
106  MatrixType obsMat, msiVect;
107  obsMat.SetSize(1, obs.GetSize());
108  msiVect.SetSize(1, msi.GetSize());
109  for (unsigned int i = 0; i < msi.GetSize(); ++i)
110  {
111  msiVect(0, i) = msi[i];
112  }
113  obsMat = msiVect * m_CovarianceInvMatrix;
114  obsMat *= 2 * (1 - m_Lambda);
115  MatrixType PanVect;
116  PanVect = m_Beta.GetTranspose();
117  PanVect *= (p - m_Alpha);
118  PanVect /= m_S;
119  PanVect *= 2 * m_Lambda;
120 
125  if ((obsMat.Cols() != PanVect.Cols()) || (obsMat.Rows() != PanVect.Rows()))
126  {
127  itkGenericExceptionMacro(<< "Matrix with size (" << obsMat.Rows() << "," << obsMat.Cols() << ") cannot be subtracted from matrix with size ("
128  << PanVect.Rows() << "," << PanVect.Cols() << " )");
129  }
131 
132  for (unsigned int r = 0; r < obsMat.Rows(); ++r)
133  {
134  for (unsigned int c = 0; c < obsMat.Cols(); ++c)
135  {
136  obsMat(r, c) += PanVect(r, c);
137  }
138  }
140  obsMat *= m_Vcondopt;
141  for (unsigned int i = 0; i < obs.GetSize(); ++i)
142  {
143  obs[i] = static_cast<typename TOutput::ValueType>(obsMat(0U, i));
144  }
145  }
147 
148  constexpr size_t OutputSize(const std::array<size_t, 3> inputsNbBands) const
149  {
150  return inputsNbBands[1];
151  }
152 
153 private:
154  float m_Lambda;
155  float m_S;
156  float m_Alpha;
160 };
161 }
162 
163 /***** TODO ***
164  * Complete the description with J. Radoux text
165  */
166 
167 /***** END TODO ***/
168 
194 template <class TInputMultiSpectralImage, class TInputMultiSpectralInterpImage, class TInputPanchroImage, class TOutputImage>
195 class ITK_EXPORT BayesianFusionFilter
196  : public FunctorImageFilter<Functor::BayesianFunctor<typename TInputMultiSpectralImage::PixelType, typename TInputMultiSpectralInterpImage::PixelType,
197  typename TInputPanchroImage::PixelType, typename TOutputImage::PixelType>>
198 {
199 public:
201  itkStaticConstMacro(InputImageDimension, unsigned int, TInputMultiSpectralImage::ImageDimension);
202  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
204 
206  typedef TInputMultiSpectralImage InputMultiSpectralImageType;
207  typedef TInputMultiSpectralInterpImage InputMultiSpectralInterpImageType;
208  typedef TInputPanchroImage InputPanchroImageType;
209  typedef TOutputImage OutputImageType;
210 
213  using BayesianFunctorType = Functor::BayesianFunctor<typename TInputMultiSpectralImage::PixelType, typename TInputMultiSpectralInterpImage::PixelType,
214  typename TInputPanchroImage::PixelType, typename TOutputImage::PixelType>;
216  typedef itk::SmartPointer<Self> Pointer;
217  typedef itk::SmartPointer<const Self> ConstPointer;
218 
220  itkNewMacro(Self);
221 
224 
226  typedef typename InputMultiSpectralImageType::PixelType InputMultiSpectralPixelType;
227  typedef typename InputMultiSpectralImageType::InternalPixelType InputMultiSpectralInternalPixelType;
228  typedef typename InputMultiSpectralInterpImageType::PixelType InputMultiSpectralInterpPixelType;
229  typedef typename InputMultiSpectralInterpImageType::InternalPixelType InputMultiSpectralInterpInternalPixelType;
230  typedef typename InputPanchroImageType::PixelType InputPanchroPixelType;
231  typedef typename OutputImageType::PixelType OutputPixelType;
232  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
233 
235  typedef typename itk::NumericTraits<InputPanchroPixelType>::RealType InputPanchroRealType;
236  typedef typename itk::NumericTraits<InputMultiSpectralInternalPixelType>::RealType InputMultiSpectralRealType;
237  typedef typename InputMultiSpectralImageType::RegionType InputMultiSpectralImageRegionType;
238  typedef typename itk::NumericTraits<InputMultiSpectralInterpInternalPixelType>::RealType InputMultiSpectralInterpRealType;
239  typedef typename InputMultiSpectralInterpImageType::RegionType InputMultiSpectralInterpImageRegionType;
240  typedef typename InputPanchroImageType::RegionType InputPanchroImageRegionType;
241  typedef typename OutputImageType::RegionType OutputImageRegionType;
242 
244  typedef typename InputMultiSpectralImageType::SizeType SizeType;
245 
251 
253  {
254  this->template SetInput<0>(multiSpect);
255  }
256 
258  {
259  this->template SetInput<1>(multiSpectInterp);
260  }
261 
262  void SetPanchro(const InputPanchroImageType* panchro)
263  {
264  this->template SetInput<2>(panchro);
265  }
266 
268  {
269  return this->template GetInput<0>();
270  }
271 
273  {
274  return this->template GetInput<1>();
275  }
276 
278  {
279  return this->template GetInput<2>();
280  }
281 
283  itkSetMacro(Lambda, float);
284 
286  itkGetConstReferenceMacro(Lambda, float);
287 
289  itkSetMacro(Beta, MatrixType);
290 
292  itkGetConstReferenceMacro(Beta, MatrixType);
293 
295  itkSetMacro(CovarianceMatrix, MatrixType);
296 
298  itkGetConstReferenceMacro(CovarianceMatrix, MatrixType);
299 
301  itkSetMacro(CovarianceInvMatrix, MatrixType);
302 
304  itkGetConstReferenceMacro(CovarianceInvMatrix, MatrixType);
305 
307  itkSetMacro(Vcondopt, MatrixType);
308 
310  itkGetConstReferenceMacro(Vcondopt, MatrixType);
311 
313  itkSetMacro(S, float);
314 
316  itkGetConstReferenceMacro(S, float);
317 
318 protected:
320  {
321  m_Lambda = 0.9999;
322  m_S = 1;
323  m_StatisticsHaveBeenGenerated = false;
324  };
325 
326  ~BayesianFusionFilter() override{};
328  void BeforeThreadedGenerateData() override;
329 
331  void ComputeInternalStatistics(void);
332 
335  void Modified(void) const override;
336 
337 private:
339  float m_Lambda;
340  float m_S;
341 
344 
347 
350 
353 
356 };
357 
358 } // end namespace otb
359 
360 #ifndef OTB_MANUAL_INSTANTIATION
362 #endif
363 
364 #endif
otb::BayesianFusionFilter::Superclass
FunctorImageFilter< BayesianFunctorType > Superclass
Definition: otbBayesianFusionFilter.h:215
otb::BayesianFusionFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbBayesianFusionFilter.h:241
otb::StreamingMatrixTransposeMatrixImageFilter
This class streams the whole input image through the PersistentMatrixTransposeMatrixImageFilter.
Definition: otbStreamingMatrixTransposeMatrixImageFilter.h:216
otbImageToVectorImageCastFilter.h
otb::BayesianFusionFilter::SizeType
InputMultiSpectralImageType::SizeType SizeType
Definition: otbBayesianFusionFilter.h:244
otb::ImageToVectorImageCastFilter
This is a helper class that convert an otb::Image into a single-channel otb::VectorImage.
Definition: otbImageToVectorImageCastFilter.h:79
otb::BayesianFusionFilter::GetMultiSpectInterp
const InputMultiSpectralInterpImageType * GetMultiSpectInterp()
Definition: otbBayesianFusionFilter.h:272
otb::Functor::BayesianFunctor::BayesianFunctor
BayesianFunctor()
Definition: otbBayesianFusionFilter.h:46
otbBayesianFusionFilter.hxx
otb::BayesianFusionFilter::m_CovarianceMatrix
MatrixType m_CovarianceMatrix
Definition: otbBayesianFusionFilter.h:343
otbFunctorImageFilter.h
otb::Functor::BayesianFunctor::m_Beta
MatrixType m_Beta
Definition: otbBayesianFusionFilter.h:158
otbVectorImage.h
otb::Functor::BayesianFunctor::SetLambda
void SetLambda(float lambda)
Definition: otbBayesianFusionFilter.h:55
otbStreamingStatisticsVectorImageFilter.h
otb::BayesianFusionFilter::m_Lambda
float m_Lambda
Definition: otbBayesianFusionFilter.h:339
otb::Functor::BayesianFunctor::~BayesianFunctor
virtual ~BayesianFunctor()
Definition: otbBayesianFusionFilter.h:49
otb::BayesianFusionFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbBayesianFusionFilter.h:217
otb::BayesianFusionFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbBayesianFusionFilter.h:216
otb::BayesianFusionFilter::m_CovarianceInvMatrix
MatrixType m_CovarianceInvMatrix
Definition: otbBayesianFusionFilter.h:346
otb::BayesianFusionFilter::m_StatisticsHaveBeenGenerated
bool m_StatisticsHaveBeenGenerated
Definition: otbBayesianFusionFilter.h:355
otb::Functor::BayesianFunctor::GetLambda
float GetLambda()
Definition: otbBayesianFusionFilter.h:79
otbStreamingMatrixTransposeMatrixImageFilter.h
otb::Functor::BayesianFunctor::MatrixType
itk::VariableSizeMatrix< RealType > MatrixType
Definition: otbBayesianFusionFilter.h:53
otb::FunctorImageFilter
A generic functor filter templated by its functor.
Definition: otbFunctorImageFilter.h:322
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::BayesianFusionFilter::InputMultiSpectralInternalPixelType
InputMultiSpectralImageType::InternalPixelType InputMultiSpectralInternalPixelType
Definition: otbBayesianFusionFilter.h:227
otb::Functor::BayesianFunctor::m_Lambda
float m_Lambda
Definition: otbBayesianFusionFilter.h:154
otb::BayesianFusionFilter::InputMultiSpectralInterpRealType
itk::NumericTraits< InputMultiSpectralInterpInternalPixelType >::RealType InputMultiSpectralInterpRealType
Definition: otbBayesianFusionFilter.h:238
otb::BayesianFusionFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbBayesianFusionFilter.h:209
otb::BayesianFusionFilter::InputMultiSpectralInterpImageType
TInputMultiSpectralInterpImage InputMultiSpectralInterpImageType
Definition: otbBayesianFusionFilter.h:207
otb::StreamingStatisticsVectorImageFilter::MatrixType
StatFilterType::MatrixType MatrixType
Definition: otbStreamingStatisticsVectorImageFilter.h:322
otb::BayesianFusionFilter::InputMultiSpectralInterpInternalPixelType
InputMultiSpectralInterpImageType::InternalPixelType InputMultiSpectralInterpInternalPixelType
Definition: otbBayesianFusionFilter.h:229
otb::Functor::BayesianFunctor::m_S
float m_S
Definition: otbBayesianFusionFilter.h:155
otb::BayesianFusionFilter::SetMultiSpect
void SetMultiSpect(const InputMultiSpectralImageType *multiSpect)
Definition: otbBayesianFusionFilter.h:252
otb::Functor::BayesianFunctor::m_CovarianceInvMatrix
MatrixType m_CovarianceInvMatrix
Definition: otbBayesianFusionFilter.h:157
otb::Functor::BayesianFunctor::OutputSize
constexpr vcl_size_t OutputSize(const std::array< vcl_size_t, 3 > inputsNbBands) const
Definition: otbBayesianFusionFilter.h:148
otb::BayesianFusionFilter::InputPanchroImageRegionType
InputPanchroImageType::RegionType InputPanchroImageRegionType
Definition: otbBayesianFusionFilter.h:240
otb::BayesianFusionFilter::~BayesianFusionFilter
~BayesianFusionFilter() override
Definition: otbBayesianFusionFilter.h:326
otb::BayesianFusionFilter::OutputInternalPixelType
OutputImageType::InternalPixelType OutputInternalPixelType
Definition: otbBayesianFusionFilter.h:232
otb::Functor::BayesianFunctor::RealType
TInputMultiSpectral::RealValueType RealType
Definition: otbBayesianFusionFilter.h:52
otb::Functor::BayesianFunctor::GetBeta
MatrixType GetBeta()
Definition: otbBayesianFusionFilter.h:91
otb::BayesianFusionFilter::BayesianFusionFilter
BayesianFusionFilter()
Definition: otbBayesianFusionFilter.h:319
otb::BayesianFusionFilter
Bayesian fusion filter. Contribution of Julien Radoux.
Definition: otbBayesianFusionFilter.h:195
otb::BayesianFusionFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbBayesianFusionFilter.h:231
otb::StreamingStatisticsVectorImageFilter
This class streams the whole input image through the PersistentStatisticsImageFilter.
Definition: otbStreamingStatisticsVectorImageFilter.h:297
otb::Functor::BayesianFunctor::m_Vcondopt
MatrixType m_Vcondopt
Definition: otbBayesianFusionFilter.h:159
otb::BayesianFusionFilter::InputMultiSpectralPixelType
InputMultiSpectralImageType::PixelType InputMultiSpectralPixelType
Definition: otbBayesianFusionFilter.h:223
otb::BayesianFusionFilter::StreamingStatisticsVectorImageFilterType
StreamingStatisticsVectorImageFilter< InputMultiSpectralInterpImageType > StreamingStatisticsVectorImageFilterType
Definition: otbBayesianFusionFilter.h:247
otb::BayesianFusionFilter::InputMultiSpectralImageType
TInputMultiSpectralImage InputMultiSpectralImageType
Definition: otbBayesianFusionFilter.h:206
otb::Functor::BayesianFunctor::SetBeta
void SetBeta(MatrixType matrix)
Definition: otbBayesianFusionFilter.h:67
otb::Functor::BayesianFunctor::m_Alpha
float m_Alpha
Definition: otbBayesianFusionFilter.h:156
otb::BayesianFusionFilter::MatrixType
StreamingStatisticsVectorImageFilterType::MatrixType MatrixType
Definition: otbBayesianFusionFilter.h:248
otb::Functor::BayesianFunctor::operator()
void operator()(TOutput &obs, const TInputMultiSpectral &, const TInputMultiSpectralInterp &msi, const TInputPanchro &p)
Definition: otbBayesianFusionFilter.h:104
otb::BayesianFusionFilter::InputPanchroPixelType
InputPanchroImageType::PixelType InputPanchroPixelType
Definition: otbBayesianFusionFilter.h:230
otb::BayesianFusionFilter::GetPanchro
const InputPanchroImageType * GetPanchro()
Definition: otbBayesianFusionFilter.h:277
otb::BayesianFusionFilter::m_S
float m_S
Definition: otbBayesianFusionFilter.h:340
otb::BayesianFusionFilter::MSTransposeMSType
StreamingMatrixTransposeMatrixImageFilter< InputMultiSpectralImageType, InputMultiSpectralImageType > MSTransposeMSType
Definition: otbBayesianFusionFilter.h:249
otb::Functor::BayesianFunctor::GetVcondopt
MatrixType GetVcondopt()
Definition: otbBayesianFusionFilter.h:99
otb::BayesianFusionFilter::CasterType
ImageToVectorImageCastFilter< InputPanchroImageType, InputMultiSpectralImageType > CasterType
Definition: otbBayesianFusionFilter.h:250
otb::Functor::BayesianFunctor::SetCovarianceInvMatrix
void SetCovarianceInvMatrix(MatrixType matrix)
Definition: otbBayesianFusionFilter.h:71
otb::BayesianFusionFilter::InputPanchroImageType
TInputPanchroImage InputPanchroImageType
Definition: otbBayesianFusionFilter.h:208
otb::BayesianFusionFilter::Self
BayesianFusionFilter Self
Definition: otbBayesianFusionFilter.h:212
otb::Functor::BayesianFunctor::GetAlpha
float GetAlpha()
Definition: otbBayesianFusionFilter.h:83
otb::BayesianFusionFilter::InputMultiSpectralInterpPixelType
InputMultiSpectralInterpImageType::PixelType InputMultiSpectralInterpPixelType
Definition: otbBayesianFusionFilter.h:228
otb::BayesianFusionFilter::InputMultiSpectralInterpImageRegionType
InputMultiSpectralInterpImageType::RegionType InputMultiSpectralInterpImageRegionType
Definition: otbBayesianFusionFilter.h:239
otb::BayesianFusionFilter::InputMultiSpectralRealType
itk::NumericTraits< InputMultiSpectralInternalPixelType >::RealType InputMultiSpectralRealType
Definition: otbBayesianFusionFilter.h:236
otb::BayesianFusionFilter::m_Beta
MatrixType m_Beta
Definition: otbBayesianFusionFilter.h:349
otb::BayesianFusionFilter::m_Vcondopt
MatrixType m_Vcondopt
Definition: otbBayesianFusionFilter.h:352
otb::BayesianFusionFilter::SetMultiSpectInterp
void SetMultiSpectInterp(const InputMultiSpectralInterpImageType *multiSpectInterp)
Definition: otbBayesianFusionFilter.h:257
otb::Functor::BayesianFunctor::SetS
void SetS(float S)
Definition: otbBayesianFusionFilter.h:59
otb::Functor::BayesianFunctor::SetAlpha
void SetAlpha(float alpha)
Definition: otbBayesianFusionFilter.h:63
otb::BayesianFusionFilter::InputPanchroRealType
itk::NumericTraits< InputPanchroPixelType >::RealType InputPanchroRealType
Definition: otbBayesianFusionFilter.h:235
otb::Functor::BayesianFunctor::GetCovarianceInvMatrix
MatrixType GetCovarianceInvMatrix()
Definition: otbBayesianFusionFilter.h:95
otb::Functor::BayesianFunctor::SetVcondopt
void SetVcondopt(MatrixType matrix)
Definition: otbBayesianFusionFilter.h:75
otb::Functor::BayesianFunctor::GetS
float GetS()
Definition: otbBayesianFusionFilter.h:87
otb::Functor::BayesianFunctor
Functor for the bayesian fusion filter. Please refer to BayesianFusionFilter.
Definition: otbBayesianFusionFilter.h:43
otb::BayesianFusionFilter::SetPanchro
void SetPanchro(const InputPanchroImageType *panchro)
Definition: otbBayesianFusionFilter.h:262
otb::BayesianFusionFilter::InputMultiSpectralImageRegionType
InputMultiSpectralImageType::RegionType InputMultiSpectralImageRegionType
Definition: otbBayesianFusionFilter.h:237
otb::BayesianFusionFilter::GetMultiSpect
const InputMultiSpectralImageType * GetMultiSpect()
Definition: otbBayesianFusionFilter.h:267