Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkHistogramToEntropyImageFilter_h
00018 #define __itkHistogramToEntropyImageFilter_h
00019
00020 #include "itkHistogramToImageFilter.h"
00021
00022 namespace itk
00023 {
00024
00051 namespace Function {
00052 template< class TInput, class TOutput=double >
00053 class HistogramEntropyFunction
00054 {
00055 public:
00056
00057
00058
00059
00060
00061 typedef TOutput OutputPixelType;
00062
00063
00064 HistogramEntropyFunction():
00065 m_TotalFrequency(1) {}
00066
00067 ~HistogramEntropyFunction() {};
00068
00069 inline OutputPixelType operator()( const TInput & A ) const
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, unsigned int NDimension, class TOutputPixel=double >
00101 class ITK_EXPORT HistogramToEntropyImageFilter :
00102 public HistogramToImageFilter< THistogram, NDimension,
00103 Function::HistogramEntropyFunction< unsigned long, TOutputPixel > >
00104 {
00105 public:
00106
00108 typedef HistogramToEntropyImageFilter Self;
00109
00111 typedef HistogramToImageFilter< THistogram, NDimension,
00112 Function::HistogramEntropyFunction< unsigned long, TOutputPixel > >
00113 Superclass;
00114
00115 typedef SmartPointer<Self> Pointer;
00116 typedef SmartPointer<const Self> ConstPointer;
00117
00119 itkTypeMacro( HistogramToEntropyImageFilter, HistogramToImageFilter );
00120
00122 itkNewMacro(Self);
00123
00124 protected:
00125 HistogramToEntropyImageFilter() {}
00126 virtual ~HistogramToEntropyImageFilter() {}
00127
00128 private:
00129 HistogramToEntropyImageFilter(const Self&);
00130 void operator=(const Self&);
00131
00132 };
00133
00134 }
00135
00136 #endif
00137