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