00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkHistogramEntropyFunction_h
00018 #define __itkHistogramEntropyFunction_h
00019
00020 #include "itkHistogramToImageFilter.h"
00021
00022 namespace itk
00023 {
00024
00051 namespace Function {
00052 template< class TInput>
00053 class HistogramEntropyFunction
00054 {
00055 public:
00056
00057
00058
00059
00060
00061 typedef double OutputPixelType;
00062
00063
00064 HistogramEntropyFunction():
00065 m_TotalFrequency(1) {}
00066
00067 ~HistogramEntropyFunction() {};
00068
00069 inline OutputPixelType operator()( const TInput & A )
00070 {
00071 if( A )
00072 {
00073 const double p = static_cast<OutputPixelType>(A) /
00074 static_cast<OutputPixelType>(m_TotalFrequency);
00075 return static_cast<OutputPixelType>( (-1) * p * vcl_log(p) / vcl_log(2.0));
00076 }
00077 else
00078 {
00079 const double p = static_cast<OutputPixelType>(A+1) /
00080 static_cast<OutputPixelType>(m_TotalFrequency);
00081 return static_cast<OutputPixelType>( (-1) * p * vcl_log(p) / vcl_log(2.0));
00082 }
00083 }
00084
00085 void SetTotalFrequency( const unsigned long n )
00086 {
00087 m_TotalFrequency = n;
00088 }
00089
00090 unsigned long GetTotalFrequency() const
00091 {
00092 return m_TotalFrequency;
00093 }
00094
00095 private:
00096 unsigned long m_TotalFrequency;
00097 };
00098 }
00099
00100 template <class THistogram >
00101 class ITK_EXPORT HistogramToEntropyImageFilter :
00102 public HistogramToImageFilter< THistogram,
00103 Function::HistogramEntropyFunction< unsigned long> >
00104 {
00105 public:
00106
00108 typedef HistogramToEntropyImageFilter Self;
00109 typedef SmartPointer<Self> Pointer;
00110 typedef SmartPointer<const Self> ConstPointer;
00111
00113 itkNewMacro(Self);
00114
00115 protected:
00116 HistogramToEntropyImageFilter() {}
00117 virtual ~HistogramToEntropyImageFilter() {}
00118
00119 private:
00120 HistogramToEntropyImageFilter(const Self&);
00121 void operator=(const Self&);
00122
00123 };
00124
00125 }
00126
00127 #endif
00128
00129
00130
00131