00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkHistogramToProbabilityImageFilter.h,v $ 00005 Language: C++ 00006 Date: $Date: 2005/04/08 21:32:05 $ 00007 Version: $Revision: 1.3 $ 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 itkNewMacro(Self); 00099 00100 protected: 00101 HistogramToProbabilityImageFilter() {} 00102 virtual ~HistogramToProbabilityImageFilter() {} 00103 00104 private: 00105 HistogramToProbabilityImageFilter(const Self&); //purposely not implemented 00106 void operator=(const Self&); //purposely not implemented 00107 00108 }; 00109 00110 } // end namespace itk 00111 00112 #endif 00113 00114 00115 00116