ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkHistogramToEntropyImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkHistogramToEntropyImageFilter_h
19 #define __itkHistogramToEntropyImageFilter_h
20 
22 
23 namespace itk
24 {
52 namespace Function
53 {
54 template< class TInput, class TOutput = double >
56 {
57 public:
58 
59  //Probability function = Number of occurrences in each bin /
60  // Total Number of occurrences.
61  //
62  // Returns pixels of float..
63  typedef TOutput OutputPixelType;
64 
66  m_TotalFrequency(1) {}
67 
69 
70  inline OutputPixelType operator()(const TInput & A) const
71  {
72  if ( A )
73  {
74  const double p = static_cast< OutputPixelType >( A )
75  / static_cast< OutputPixelType >( m_TotalFrequency );
76  return static_cast< OutputPixelType >( ( -1 ) * p * vcl_log(p) / vcl_log(2.0) );
77  }
78  else
79  {
80  const double p = static_cast< OutputPixelType >( A + 1 )
81  / static_cast< OutputPixelType >( m_TotalFrequency );
82  return static_cast< OutputPixelType >( ( -1 ) * p * vcl_log(p) / vcl_log(2.0) );
83  }
84  }
85 
87  {
88  m_TotalFrequency = n;
89  }
90 
92  {
93  return m_TotalFrequency;
94  }
95 
96 private:
98 };
99 }
100 
101 template< class THistogram, class TImage=Image< double, 3> >
103  public HistogramToImageFilter< THistogram, TImage,
104  Function::HistogramEntropyFunction< SizeValueType, typename TImage::PixelType > >
105 {
106 public:
107 
110 
112  typedef HistogramToImageFilter< THistogram, TImage,
115 
118 
121 
123  itkNewMacro(Self);
124 
125 protected:
128 
129 private:
130  HistogramToEntropyImageFilter(const Self &); //purposely not implemented
131  void operator=(const Self &); //purposely not implemented
132 };
133 } // end namespace itk
134 
135 #endif
136