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

itkHistogramToLogProbabilityImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkHistogramToLogProbabilityImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-01-17 09:13:59 $
00007   Version:   $Revision: 1.8 $
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 __itkHistogramLogProbabilityFunction_h
00018 #define __itkHistogramLogProbabilityFunction_h
00019 
00020 #include "itkHistogramToImageFilter.h"
00021 
00022 namespace itk
00023 {
00024   
00046 namespace Function {  
00047 template< class TInput, class TOutput=double >
00048 class HistogramLogProbabilityFunction
00049 {
00050 public:
00051   
00052   //Probability function = Number of occurances in each bin /
00053   //   Total Number of occurances. 
00054   //
00055   // Returns pixels of float.. 
00056   typedef  TOutput  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)) / vcl_log(2.0) );
00070       }
00071     else
00072       { // Check for Log 0. Always assume that the frequency is atleast 1.
00073       return static_cast<OutputPixelType>(log( static_cast<OutputPixelType>(A+1) / 
00074         static_cast<OutputPixelType>(m_TotalFrequency)) / vcl_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, class TOutputPixel=double >
00095 class ITK_EXPORT HistogramToLogProbabilityImageFilter :
00096   public HistogramToImageFilter< THistogram, 
00097   Function::HistogramLogProbabilityFunction< unsigned long, TOutputPixel > > 
00098 {
00099 public:
00100   
00102   typedef HistogramToLogProbabilityImageFilter Self;
00103 
00105   typedef HistogramToImageFilter< THistogram, 
00106     Function::HistogramLogProbabilityFunction< unsigned long, TOutputPixel > >
00107                                                Superclass;
00108 
00109   typedef SmartPointer<Self>                   Pointer;
00110   typedef SmartPointer<const Self>             ConstPointer;
00111   
00113   itkTypeMacro( HistogramToLogProbabilityImageFilter, HistogramToImageFilter );
00114 
00116   itkNewMacro(Self);
00117 
00118 protected:
00119   HistogramToLogProbabilityImageFilter() {}
00120   virtual ~HistogramToLogProbabilityImageFilter() {}
00121   
00122 private:
00123   HistogramToLogProbabilityImageFilter(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 Sat Feb 28 12:36:25 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000