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: 2007/10/27 19:51:47 $
00007   Version:   $Revision: 1.6 $
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   itkTypeMacro( HistogramToEntropyImageFilter, HistogramToImageFilter );
00114 
00116   itkNewMacro(Self);
00117 
00118 protected:
00119   HistogramToEntropyImageFilter() {}
00120   virtual ~HistogramToEntropyImageFilter() {}
00121   
00122 private:
00123   HistogramToEntropyImageFilter(const Self&); //purposely not implemented
00124   void operator=(const Self&); //purposely not implemented
00125 
00126 };
00127 
00128 } // end namespace itk
00129 
00130 #endif
00131 
00132 
00133 
00134 

Generated at Tue Jul 29 20:23:15 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000