OTB  9.0.0
Orfeo Toolbox
otbKullbackLeiblerProfileImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
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 otbKullbackLeiblerProfileImageFilter_h
23 #define otbKullbackLeiblerProfileImageFilter_h
24 
25 #include <vector>
26 
27 #include "itkArray.h"
28 #include "itkArray2D.h"
29 #include "itkVariableLengthVector.h"
30 
32 
33 namespace otb
34 {
35 
42 template <class TInput>
44 {
45 public:
46  typedef itk::Vector<double, 4> CumulantType;
47  typedef std::vector<CumulantType> CumulantSet;
48  typedef CumulantSet::iterator Iterator;
49 
50  CumulantsForEdgeworthProfile(const TInput& input, std::vector<itk::Array2D<int>>& mask);
52  {
53  }
54 
55  // Kullback-Leibler Profile
56  template <class TInput2>
57  itk::VariableLengthVector<double> KL_profile(CumulantsForEdgeworthProfile<TInput2>& cumulants);
58  // Kullback-Leibler divergence at a given scale
59  double KL_profile(const CumulantType& cumulants1, const CumulantType& cumulants2);
60  // Access to data
62  {
63  return this->fCum[i];
64  }
65  // Check data availability
66  inline bool IsDataAvailable() const
67  {
68  return this->fDataAvailable;
69  }
70 
71  // debug
72  int m_debug;
73 
74 protected:
75  // Momentum Estimation from encapsulated neighborhood
76  int MakeSumAndMoments(const TInput& input, std::vector<itk::Array2D<int>>& mask);
77  // momentum estimation from the smaller window
78  int InitSumAndMoments(const TInput& input, itk::Array2D<int>& mask);
79  //
80  int ReInitSumAndMoments(const TInput& input, itk::Array2D<int>& mask, int level);
81  // transformation moment -> cumulants (for Edgeworth)
82  int MakeCumulants();
83 
84  // Internal variables
85  double fSum0, fSum1, fSum2, fSum3, fSum4;
88 
90 
91 private:
92  CumulantsForEdgeworthProfile(); // Not implemented
93  CumulantsForEdgeworthProfile(const TInput& input); // Not implemented
94 };
95 
96 namespace Functor
97 {
104 template <class TInput1, class TInput2, class TOutput>
106 {
107 public:
110  {
111  }
112  // Gives the radius min and max of neighborhood
113  void SetRadius(const unsigned char& min, const unsigned char& max);
114  unsigned char GetRadiusMin(void);
115  unsigned char GetRadiusMax(void);
116  // Gives the size of the profile
118  {
119  return m_mask.size();
120  }
121  // functor
122  TOutput operator()(const TInput1& it1, const TInput2& it2);
123 
124 protected:
125  // Make the set of masks to play the increase in window size
126  void MakeMultiscaleProfile();
127  // Internal attributes
128  unsigned char m_RadiusMin;
129  unsigned char m_RadiusMax;
130  std::vector<itk::Array2D<int>> m_mask;
131 };
132 } // Functor
133 
166 template <class TInputImage1, class TInputImage2, class TOutputImage>
169  TInputImage1, TInputImage2, TOutputImage,
170  Functor::KullbackLeiblerProfile<typename itk::ConstNeighborhoodIterator<TInputImage1>, typename itk::ConstNeighborhoodIterator<TInputImage2>,
171  typename TOutputImage::PixelType>>
172 {
173 public:
176  typedef /*typename*/ BinaryFunctorNeighborhoodVectorImageFilter<
177  TInputImage1, TInputImage2, TOutputImage,
178  Functor::KullbackLeiblerProfile<typename itk::ConstNeighborhoodIterator<TInputImage1>, typename itk::ConstNeighborhoodIterator<TInputImage2>,
179  typename TOutputImage::PixelType>>
181  typedef itk::SmartPointer<Self> Pointer;
182  typedef itk::SmartPointer<const Self> ConstPointer;
183 
185  itkNewMacro(Self);
186 
187 protected:
189  {
190  }
192  {
193  }
194 
195 private:
196  KullbackLeiblerProfileImageFilter(const Self&) = delete;
197  void operator=(const Self&) = delete;
198 };
199 
200 } // namespace otb
201 
202 #ifndef OTB_MANUAL_INSTANTIATION
204 #endif
205 
206 #endif
otb::Functor::KullbackLeiblerProfile::operator()
TOutput operator()(const TInput1 &it1, const TInput2 &it2)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:391
otb::CumulantsForEdgeworthProfile::fSum2
double fSum2
Definition: otbKullbackLeiblerProfileImageFilter.h:85
otbBinaryFunctorNeighborhoodVectorImageFilter.h
otb::CumulantsForEdgeworthProfile::InitSumAndMoments
int InitSumAndMoments(const TInput &input, itk::Array2D< int > &mask)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:139
otb::CumulantsForEdgeworthProfile::CumulantSet
std::vector< CumulantType > CumulantSet
Definition: otbKullbackLeiblerProfileImageFilter.h:47
otb::CumulantsForEdgeworthProfile::~CumulantsForEdgeworthProfile
virtual ~CumulantsForEdgeworthProfile()
Definition: otbKullbackLeiblerProfileImageFilter.h:51
otb::CumulantsForEdgeworthProfile::fSum0
double fSum0
Definition: otbKullbackLeiblerProfileImageFilter.h:85
otb::CumulantsForEdgeworthProfile::fDataAvailable
bool fDataAvailable
Definition: otbKullbackLeiblerProfileImageFilter.h:89
otb::CumulantsForEdgeworthProfile::fSum4
double fSum4
Definition: otbKullbackLeiblerProfileImageFilter.h:85
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::KullbackLeiblerProfile::MakeMultiscaleProfile
void MakeMultiscaleProfile()
Definition: otbKullbackLeiblerProfileImageFilter.hxx:352
otb::CumulantsForEdgeworthProfile::fSum3
double fSum3
Definition: otbKullbackLeiblerProfileImageFilter.h:85
otb::KullbackLeiblerProfileImageFilter::Superclass
BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< typename itk::ConstNeighborhoodIterator< TInputImage1 >, typename itk::ConstNeighborhoodIterator< TInputImage2 >, typename TOutputImage::PixelType > > Superclass
Definition: otbKullbackLeiblerProfileImageFilter.h:180
otb::CumulantsForEdgeworthProfile::CumulantsForEdgeworthProfile
CumulantsForEdgeworthProfile()
otb::BinaryFunctorNeighborhoodVectorImageFilter
Implements neighborhood-wise generic operation of two images being vector images.
Definition: otbBinaryFunctorNeighborhoodVectorImageFilter.h:42
otb::Functor::KullbackLeiblerProfile::m_mask
std::vector< itk::Array2D< int > > m_mask
Definition: otbKullbackLeiblerProfileImageFilter.h:130
otb::KullbackLeiblerProfileImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbKullbackLeiblerProfileImageFilter.h:181
otb::CumulantsForEdgeworthProfile::KL_profile
itk::VariableLengthVector< double > KL_profile(CumulantsForEdgeworthProfile< TInput2 > &cumulants)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:48
otb::KullbackLeiblerProfileImageFilter::Self
KullbackLeiblerProfileImageFilter Self
Definition: otbKullbackLeiblerProfileImageFilter.h:175
otb::Functor::KullbackLeiblerProfile::GetRadiusMin
unsigned char GetRadiusMin(void)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:338
otb::KullbackLeiblerProfileImageFilter::KullbackLeiblerProfileImageFilter
KullbackLeiblerProfileImageFilter()
Definition: otbKullbackLeiblerProfileImageFilter.h:188
otb::CumulantsForEdgeworthProfile::fSum1
double fSum1
Definition: otbKullbackLeiblerProfileImageFilter.h:85
otb::CumulantsForEdgeworthProfile::CumulantType
itk::Vector< double, 4 > CumulantType
Definition: otbKullbackLeiblerProfileImageFilter.h:46
otb::CumulantsForEdgeworthProfile::fMu
CumulantSet fMu
Definition: otbKullbackLeiblerProfileImageFilter.h:86
otb::KullbackLeiblerProfileImageFilter::~KullbackLeiblerProfileImageFilter
~KullbackLeiblerProfileImageFilter() override
Definition: otbKullbackLeiblerProfileImageFilter.h:191
otb::Functor::KullbackLeiblerProfile::m_RadiusMax
unsigned char m_RadiusMax
Definition: otbKullbackLeiblerProfileImageFilter.h:129
otb::Functor::KullbackLeiblerProfile::m_RadiusMin
unsigned char m_RadiusMin
Definition: otbKullbackLeiblerProfileImageFilter.h:128
otb::Functor::KullbackLeiblerProfile
Functor for KullbackLeiblerProfileImageFilter. Please refer to KullbackLeiblerProfileImageFilter.
Definition: otbKullbackLeiblerProfileImageFilter.h:105
otb::CumulantsForEdgeworthProfile::ReInitSumAndMoments
int ReInitSumAndMoments(const TInput &input, itk::Array2D< int > &mask, int level)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:237
otb::CumulantsForEdgeworthProfile::Iterator
CumulantSet::iterator Iterator
Definition: otbKullbackLeiblerProfileImageFilter.h:48
otb::CumulantsForEdgeworthProfile
Helper class for KullbackLeiblerProfileImageFilter. Please refer to KullbackLeibleProfileImageFilter.
Definition: otbKullbackLeiblerProfileImageFilter.h:43
otb::KullbackLeiblerProfileImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbKullbackLeiblerProfileImageFilter.h:182
otb::CumulantsForEdgeworthProfile::MakeSumAndMoments
int MakeSumAndMoments(const TInput &input, std::vector< itk::Array2D< int >> &mask)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:120
otb::Functor::KullbackLeiblerProfile::GetNumberOfComponentsPerPixel
int GetNumberOfComponentsPerPixel() const
Definition: otbKullbackLeiblerProfileImageFilter.h:117
otb::Functor::KullbackLeiblerProfile::GetRadiusMax
unsigned char GetRadiusMax(void)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:344
otb::CumulantsForEdgeworthProfile::fCum
CumulantSet fCum
Definition: otbKullbackLeiblerProfileImageFilter.h:87
otb::CumulantsForEdgeworthProfile::MakeCumulants
int MakeCumulants()
Definition: otbKullbackLeiblerProfileImageFilter.hxx:296
otb::CumulantsForEdgeworthProfile::m_debug
int m_debug
Definition: otbKullbackLeiblerProfileImageFilter.h:72
otb::Functor::KullbackLeiblerProfile::KullbackLeiblerProfile
KullbackLeiblerProfile()
Definition: otbKullbackLeiblerProfileImageFilter.hxx:321
otb::Functor::KullbackLeiblerProfile::SetRadius
void SetRadius(const unsigned char &min, const unsigned char &max)
Definition: otbKullbackLeiblerProfileImageFilter.hxx:330
otb::CumulantsForEdgeworthProfile::IsDataAvailable
bool IsDataAvailable() const
Definition: otbKullbackLeiblerProfileImageFilter.h:66
otb::Functor::KullbackLeiblerProfile::~KullbackLeiblerProfile
virtual ~KullbackLeiblerProfile()
Definition: otbKullbackLeiblerProfileImageFilter.h:109
otbKullbackLeiblerProfileImageFilter.hxx
otb::KullbackLeiblerProfileImageFilter
Implements neighborhood-wise the computation of KullbackLeibler profile over Edgeworth approximation.
Definition: otbKullbackLeiblerProfileImageFilter.h:167
otb::CumulantsForEdgeworthProfile::GetCumulantAtScale
CumulantType & GetCumulantAtScale(int i)
Definition: otbKullbackLeiblerProfileImageFilter.h:61