OTB  10.0.0
Orfeo Toolbox
otbKullbackLeiblerProfileImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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:
197  void operator=(const Self&) = delete;
198 };
199 
200 } // namespace otb
201 
202 #ifndef OTB_MANUAL_INSTANTIATION
204 #endif
205 
206 #endif
Implements neighborhood-wise generic operation of two images being vector images.
Helper class for KullbackLeiblerProfileImageFilter. Please refer to KullbackLeibleProfileImageFilter.
int InitSumAndMoments(const TInput &input, itk::Array2D< int > &mask)
itk::VariableLengthVector< double > KL_profile(CumulantsForEdgeworthProfile< TInput2 > &cumulants)
CumulantsForEdgeworthProfile(const TInput &input)
int ReInitSumAndMoments(const TInput &input, itk::Array2D< int > &mask, int level)
int MakeSumAndMoments(const TInput &input, std::vector< itk::Array2D< int >> &mask)
Functor for KullbackLeiblerProfileImageFilter. Please refer to KullbackLeiblerProfileImageFilter.
void SetRadius(const unsigned char &min, const unsigned char &max)
TOutput operator()(const TInput1 &it1, const TInput2 &it2)
Implements neighborhood-wise the computation of KullbackLeibler profile over Edgeworth approximation.
BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< typename itk::ConstNeighborhoodIterator< TInputImage1 >, typename itk::ConstNeighborhoodIterator< TInputImage2 >, typename TOutputImage::PixelType > > Superclass
KullbackLeiblerProfileImageFilter(const Self &)=delete
void operator=(const Self &)=delete
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.