00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkHistogramToProbabilityImageFilter.h,v $ 00005 Language: C++ 00006 Date: $Date: 2007-10-27 19:51:47 $ 00007 Version: $Revision: 1.4 $ 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 __itkHistogramProbabilityFunction_h 00018 #define __itkHistogramProbabilityFunction_h 00019 00020 #include "itkHistogramToImageFilter.h" 00021 00022 namespace itk 00023 { 00024 00046 namespace Function { 00047 template< class TInput> 00048 class HistogramProbabilityFunction 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 float OutputPixelType; 00057 00058 00059 HistogramProbabilityFunction(): 00060 m_TotalFrequency(1) {} 00061 00062 ~HistogramProbabilityFunction() {}; 00063 00064 inline OutputPixelType operator()( const TInput & A ) 00065 { 00066 return static_cast<OutputPixelType>( static_cast<OutputPixelType>(A) / 00067 static_cast<OutputPixelType>(m_TotalFrequency) ); 00068 } 00069 00070 void SetTotalFrequency( unsigned long n ) 00071 { 00072 m_TotalFrequency = n; 00073 } 00074 00075 unsigned long GetTotalFrequency( ) const 00076 { 00077 return m_TotalFrequency; 00078 } 00079 00080 private: 00081 unsigned long m_TotalFrequency; 00082 }; 00083 } 00084 00085 template <class THistogram > 00086 class ITK_EXPORT HistogramToProbabilityImageFilter : 00087 public HistogramToImageFilter< THistogram, 00088 Function::HistogramProbabilityFunction< unsigned long> > 00089 { 00090 public: 00091 00093 typedef HistogramToProbabilityImageFilter Self; 00094 typedef SmartPointer<Self> Pointer; 00095 typedef SmartPointer<const Self> ConstPointer; 00096 00098 itkTypeMacro( HistogramToProbabilityImageFilter, HistogramToImageFilter ); 00099 00101 itkNewMacro(Self); 00102 00103 protected: 00104 HistogramToProbabilityImageFilter() {} 00105 virtual ~HistogramToProbabilityImageFilter() {} 00106 00107 private: 00108 HistogramToProbabilityImageFilter(const Self&); //purposely not implemented 00109 void operator=(const Self&); //purposely not implemented 00110 00111 }; 00112 00113 } // end namespace itk 00114 00115 #endif 00116 00117 00118 00119