OTB  6.1.0
Orfeo Toolbox
otbKullbackLeiblerProfileImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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"
30 
32 
33 namespace otb
34 {
35 
42 template <class TInput>
44 {
45 public:
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  // Kullback-Leibler Profile
54  template <class TInput2>
56  // Kullback-Leibler divergence at a given scale
57  double KL_profile(const CumulantType& cumulants1, const CumulantType& cumulants2);
58  // Access to data
60  {
61  return this->fCum[i];
62  }
63  // Check data availability
64  inline bool IsDataAvailable() const
65  {
66  return this->fDataAvailable;
67  }
68 
69  // debug
70  int m_debug;
71 
72 protected:
73 
74  // Momentum Estimation from encapsulated neighborhood
75  int MakeSumAndMoments(const TInput& input, std::vector<itk::Array2D<int> >& mask);
76  // momentum estimation from the smaller window
77  int InitSumAndMoments(const TInput& input, itk::Array2D<int>& mask);
78  //
79  int ReInitSumAndMoments(const TInput& input, itk::Array2D<int>& mask, int level);
80  // transformation moment -> cumulants (for Edgeworth)
81  int MakeCumulants();
82 
83  // Internal variables
84  double fSum0, fSum1, fSum2, fSum3, fSum4;
87 
89 
90 private:
91  CumulantsForEdgeworthProfile (); // Not implemented
92  CumulantsForEdgeworthProfile (const TInput& input); // Not implemented
93 
94 };
95 
96 namespace Functor
97 {
104 template<class TInput1, class TInput2, class TOutput>
106 {
107 public:
110  // Gives the radius min and max of neighborhood
111  void SetRadius(const unsigned char& min, const unsigned char& max);
112  unsigned char GetRadiusMin(void);
113  unsigned char GetRadiusMax(void);
114  // Gives the size of the profile
116  {
117  return m_mask.size();
118  }
119  // functor
120  TOutput operator ()(const TInput1& it1, const TInput2& it2);
121 protected:
122  // Make the set of masks to play the increase in window size
123  void MakeMultiscaleProfile();
124  // Internal attributes
125  unsigned char m_RadiusMin;
126  unsigned char m_RadiusMax;
127  std::vector<itk::Array2D<int> > m_mask;
128 };
129 } // Functor
130 
163 template <class TInputImage1, class TInputImage2, class TOutputImage>
166  TInputImage1, TInputImage2, TOutputImage,
167  Functor::KullbackLeiblerProfile<
168  typename itk::ConstNeighborhoodIterator<TInputImage1>,
169  typename itk::ConstNeighborhoodIterator<TInputImage2>,
170  typename TOutputImage::PixelType> >
171 {
172 public:
175  typedef /*typename*/ BinaryFunctorNeighborhoodVectorImageFilter<
176  TInputImage1, TInputImage2, TOutputImage,
180  typename TOutputImage::PixelType>
184 
186  itkNewMacro(Self);
187 
188 protected:
191 
192 private:
193  KullbackLeiblerProfileImageFilter(const Self &); //purposely not implemented
194  void operator =(const Self&); //purposely not implemented
195 
196 };
197 
198 } // namespace otb
199 
200 #ifndef OTB_MANUAL_INSTANTIATION
202 #endif
203 
204 #endif
BinaryFunctorNeighborhoodVectorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::KullbackLeiblerProfile< typename itk::ConstNeighborhoodIterator< TInputImage1 >, typename itk::ConstNeighborhoodIterator< TInputImage2 >, typename TOutputImage::PixelType > > Superclass
Implements neighborhood-wise generic operation of two images being vector images. ...
int InitSumAndMoments(const TInput &input, itk::Array2D< int > &mask)
int MakeSumAndMoments(const TInput &input, std::vector< itk::Array2D< int > > &mask)
Implements neighborhood-wise the computation of KullbackLeibler profile over Edgeworth approximation...
void SetRadius(const unsigned char &min, const unsigned char &max)
itk::VariableLengthVector< double > KL_profile(CumulantsForEdgeworthProfile< TInput2 > &cumulants)
TOutput operator()(const TInput1 &it1, const TInput2 &it2)
Functor for KullbackLeiblerProfileImageFilter. Please refer to KullbackLeiblerProfileImageFilter.
Helper class for KullbackLeiblerProfileImageFilter. Please refer to KullbackLeibleProfileImageFilter...
int ReInitSumAndMoments(const TInput &input, itk::Array2D< int > &mask, int level)