Orfeo Toolbox  3.16
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;
36  virtual ~JoinHistogramMI() {}
37  inline TOutput operator ()(const TInput1& itA,
38  const TInput2& itB, const HistogramType* histogram)
39  {
40  TOutput jointEntropy = itk::NumericTraits<TOutput>::Zero;
41  HistogramFrequencyType totalFreq = histogram->GetTotalFrequency();
42 
43  /* for(unsigned long pos = 0; pos< itA.Size(); ++pos)
44  {
45  double value = static_cast<double>(itA.GetPixel(pos));
46 
47  unsigned int bin =
48  HistogramFrequencyType freq = histogram.GetFrequency(, 0);
49  if (freq > 0)
50  {
51  entropyX += freq*vcl_log(freq);
52  }
53  }
54 
55  entropyX = -entropyX/static_cast<TOutput>(totalFreq) + vcl_log(totalFreq);
56 
57  for (unsigned int i = 0; i < this->GetHistogramSize()[1]; ++i)
58  {
59  HistogramFrequencyType freq = histogram.GetFrequency(i, 1);
60  if (freq > 0)
61  {
62  entropyY += freq*vcl_log(freq);
63  }
64  }
65 
66  entropyY = -entropyY/static_cast<TOutput>(totalFreq) + vcl_log(totalFreq);
67 
68  HistogramIteratorType it = histogram.Begin();
69  HistogramIteratorType end = histogram.End();
70  while (it != end)
71  {
72  HistogramFrequencyType freq = it.GetFrequency();
73  if (freq > 0)
74  {
75  jointEntropy += freq*vcl_log(freq);
76  }
77  ++it;
78  }
79 
80  jointEntropy = -jointEntropy/static_cast<TOutput>(totalFreq) +
81  vcl_log(totalFreq);
82 
83  return entropyX + entropyY - jointEntropy; */
84 
86  for (unsigned long pos = 0; pos < itA.Size(); ++pos)
87  {
88  double valueA = static_cast<double>(itA.GetPixel(pos));
89  double valueB = static_cast<double>(itB.GetPixel(pos));
90 
91  sample[0] = valueA;
92  sample[1] = valueB;
93 
94  HistogramFrequencyType freq = histogram->GetFrequency(
95  histogram->GetIndex(sample));
96  if (freq > 0)
97  {
98  jointEntropy += freq * vcl_log(freq);
99  }
100 
101  }
102 
103  jointEntropy = -jointEntropy / static_cast<TOutput>(totalFreq) +
104  vcl_log(totalFreq);
105 
106  return jointEntropy;
107 
108  /* TOutput meanA = 0.0;
109  TOutput meanB = 0.0;
110 
111  for(unsigned long pos = 0; pos< itA.Size(); ++pos)
112  {
113 
114  meanA += static_cast<TOutput>(itA.GetPixel(pos));
115  meanB += static_cast<TOutput>(itB.GetPixel(pos));
116 
117 
118  }*/
119  return static_cast<TOutput>(0);
120  }
121 
122  /* void SetHistogram(HistogramType* histo)
123  {
124  m_Histogram = histo;
125  }
126 
127  protected:
128  HistogramType::Pointer m_Histogram; */
129 };
130 }
131 } // end namespace otb
132 
133 #endif

Generated at Sun Feb 3 2013 00:31:40 for Orfeo Toolbox with doxygen 1.8.1.1