Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkHistogramToEntropyImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkHistogramToEntropyImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-04-01 14:36:37 $
00007   Version:   $Revision: 1.10 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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   //Probability function = Number of occurances in each bin /
00058   //   Total Number of occurances. 
00059   //
00060   // Returns pixels of float.. 
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, class TOutputPixel=double >
00101 class ITK_EXPORT HistogramToEntropyImageFilter :
00102   public HistogramToImageFilter< THistogram, 
00103   Function::HistogramEntropyFunction< unsigned long, TOutputPixel > > 
00104 {
00105 public:
00106   
00108   typedef HistogramToEntropyImageFilter Self;
00109 
00111   typedef HistogramToImageFilter< THistogram, 
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&); //purposely not implemented
00130   void operator=(const Self&); //purposely not implemented
00131 
00132 };
00133 
00134 } // end namespace itk
00135 
00136 #endif
00137 

Generated at Fri Apr 16 18:30:48 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000