Orfeo Toolbox  4.0
otbJoinHistogramMI.h
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 __otbJoinHistogramMI_h
19 #define __otbJoinHistogramMI_h
20 
21 #include "itkHistogram.h"
22 
23 namespace otb
24 {
25 
26 namespace Functor
27 {
28 
29 template<class TInput1, class TInput2, class TOutput>
31 {
32 public:
33  typedef double HistogramFrequencyType;
37  virtual ~JoinHistogramMI() {}
38  inline TOutput operator ()(const TInput1& itA,
39  const TInput2& itB, const HistogramType* histogram)
40  {
41  TOutput jointEntropy = itk::NumericTraits<TOutput>::Zero;
42  HistogramFrequencyType totalFreq = histogram->GetTotalFrequency();
43 
44  typename HistogramType::MeasurementVectorType sample(2);
45  for (unsigned long pos = 0; pos < itA.Size(); ++pos)
46  {
47  double valueA = static_cast<double>(itA.GetPixel(pos));
48  double valueB = static_cast<double>(itB.GetPixel(pos));
49 
50  sample[0] = valueA;
51  sample[1] = valueB;
52 
53  typename HistogramType::IndexType index;
54  histogram->GetIndex(sample, index);
55  HistogramFrequencyType freq = histogram->GetFrequency(index);
56  if (freq > 0)
57  {
58  jointEntropy += freq * vcl_log(freq);
59  }
60 
61  }
62 
63  jointEntropy = -jointEntropy / static_cast<TOutput>(totalFreq) +
64  vcl_log(totalFreq);
65 
66  return jointEntropy;
67  }
68 
69 };
70 }
71 } // end namespace otb
72 
73 #endif

Generated at Sat Mar 8 2014 16:02:45 for Orfeo Toolbox with doxygen 1.8.3.1