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: 2006/03/19 04:37:20 $
00007   Version:   $Revision: 1.5 $
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 __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   //Probability function = Number of occurances in each bin /
00058   //   Total Number of occurances. 
00059   //
00060   // Returns pixels of float.. 
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&); //purposely not implemented
00121   void operator=(const Self&); //purposely not implemented
00122 
00123 };
00124 
00125 } // end namespace itk
00126 
00127 #endif
00128 
00129 
00130 
00131 

Generated at Sun Sep 23 12:50:18 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000