ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkHistogramToLogProbabilityImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkHistogramToLogProbabilityImageFilter_h
00019 #define __itkHistogramToLogProbabilityImageFilter_h
00020 
00021 #include "itkHistogramToImageFilter.h"
00022 
00023 namespace itk
00024 {
00047 namespace Function
00048 {
00049 template< class TInput, class TOutput = double >
00050 class HistogramLogProbabilityFunction
00051 {
00052 public:
00053 
00054   //Probability function = Number of occurances in each bin /
00055   //   Total Number of occurances.
00056   //
00057   // Returns pixels of float..
00058   typedef  TOutput OutputPixelType;
00059 
00060   HistogramLogProbabilityFunction():
00061     m_TotalFrequency(1) {}
00062 
00063   ~HistogramLogProbabilityFunction() {}
00064 
00065   inline OutputPixelType operator()(const TInput & A) const
00066   {
00067     if ( A )
00068       {
00069       return static_cast< OutputPixelType >( vcl_log( static_cast< OutputPixelType >( A )
00070                                                       / static_cast< OutputPixelType >( m_TotalFrequency ) )
00071                                              / vcl_log(2.0) );
00072       }
00073     else
00074       {   // Check for Log 0. Always assume that the frequency is atleast 1.
00075       return static_cast< OutputPixelType >( vcl_log( static_cast< OutputPixelType >( A + 1 )
00076                                                       / static_cast< OutputPixelType >( m_TotalFrequency ) )
00077                                              / vcl_log(2.0) );
00078       }
00079   }
00080 
00081   void SetTotalFrequency(SizeValueType n)
00082   {
00083     m_TotalFrequency = n;
00084   }
00085 
00086   SizeValueType GetTotalFrequency() const
00087   {
00088     return m_TotalFrequency;
00089   }
00090 
00091 private:
00092   SizeValueType m_TotalFrequency;
00093 };
00094 }
00095 
00096 template< class THistogram, class TImage=Image< double, 3 > >
00097 class ITK_EXPORT HistogramToLogProbabilityImageFilter:
00098   public HistogramToImageFilter< THistogram, TImage,
00099                                  Function::HistogramLogProbabilityFunction< SizeValueType, typename TImage::PixelType > >
00100 {
00101 public:
00102 
00104   typedef HistogramToLogProbabilityImageFilter Self;
00105 
00107   typedef HistogramToImageFilter< THistogram, TImage,
00108                                  Function::HistogramLogProbabilityFunction< SizeValueType, typename TImage::PixelType > >
00109   Superclass;
00110 
00111   typedef SmartPointer< Self >       Pointer;
00112   typedef SmartPointer< const Self > ConstPointer;
00113 
00115   itkTypeMacro(HistogramToLogProbabilityImageFilter, HistogramToImageFilter);
00116 
00118   itkNewMacro(Self);
00119 protected:
00120   HistogramToLogProbabilityImageFilter() {}
00121   virtual ~HistogramToLogProbabilityImageFilter() {}
00122 private:
00123   HistogramToLogProbabilityImageFilter(const Self &); //purposely not
00124                                                       // implemented
00125   void operator=(const Self &);                       //purposely not
00126                                                       // implemented
00127 };
00128 } // end namespace itk
00130 
00131 #endif
00132