ITK  5.2.0
Insight Toolkit
itkHistogramToEntropyImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
53 namespace Function
54 {
55 template <typename TInput, typename TOutput = double>
57 {
58 public:
59  // Probability function = Number of occurrences in each bin /
60  // Total Number of occurrences.
61  //
62  // Returns pixels of float..
63  using OutputPixelType = TOutput;
64 
65  HistogramEntropyFunction() = default;
66 
67  ~HistogramEntropyFunction() = default;
68 
69  inline OutputPixelType
70  operator()(const TInput & A) const
71  {
72  if (A)
73  {
74  const double p = static_cast<OutputPixelType>(A) / static_cast<OutputPixelType>(m_TotalFrequency);
75  return static_cast<OutputPixelType>((-1) * p * std::log(p) / std::log(2.0));
76  }
77  else
78  {
79  const double p = static_cast<OutputPixelType>(A + 1) / static_cast<OutputPixelType>(m_TotalFrequency);
80  return static_cast<OutputPixelType>((-1) * p * std::log(p) / std::log(2.0));
81  }
82  }
83 
84  void
86  {
87  m_TotalFrequency = n;
88  }
89 
92  {
93  return m_TotalFrequency;
94  }
95 
96 private:
98 };
99 } // namespace Function
100 
101 template <typename THistogram, typename TImage = Image<double, 3>>
103  : public HistogramToImageFilter<THistogram,
104  TImage,
105  Function::HistogramEntropyFunction<SizeValueType, typename TImage::PixelType>>
106 {
107 public:
108  ITK_DISALLOW_COPY_AND_ASSIGN(HistogramToEntropyImageFilter);
109 
112 
114  using Superclass =
115  HistogramToImageFilter<THistogram,
116  TImage,
118 
121 
124 
126  itkNewMacro(Self);
127 
128 protected:
129  HistogramToEntropyImageFilter() = default;
130  ~HistogramToEntropyImageFilter() override = default;
131 };
132 } // end namespace itk
133 
134 #endif
itk::Function::HistogramEntropyFunction::SetTotalFrequency
void SetTotalFrequency(const SizeValueType n)
Definition: itkHistogramToEntropyImageFilter.h:85
itk::HistogramToEntropyImageFilter::HistogramToEntropyImageFilter
HistogramToEntropyImageFilter()=default
itkHistogramToImageFilter.h
itk::SmartPointer< Self >
itk::Function::HistogramEntropyFunction::operator()
OutputPixelType operator()(const TInput &A) const
Definition: itkHistogramToEntropyImageFilter.h:70
itk::HistogramToEntropyImageFilter
The class takes a histogram as an input and gives the entropy image as the output....
Definition: itkHistogramToEntropyImageFilter.h:102
itk::Function::HistogramEntropyFunction::m_TotalFrequency
SizeValueType m_TotalFrequency
Definition: itkHistogramToEntropyImageFilter.h:97
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Function::HistogramEntropyFunction< SizeValueType, TImage::PixelType >::OutputPixelType
TImage::PixelType OutputPixelType
Definition: itkHistogramToEntropyImageFilter.h:63
itk::Function::HistogramEntropyFunction::GetTotalFrequency
SizeValueType GetTotalFrequency() const
Definition: itkHistogramToEntropyImageFilter.h:91
itk::Function::HistogramEntropyFunction::HistogramEntropyFunction
HistogramEntropyFunction()=default
itk::HistogramToEntropyImageFilter::~HistogramToEntropyImageFilter
~HistogramToEntropyImageFilter() override=default
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Function::HistogramEntropyFunction::~HistogramEntropyFunction
~HistogramEntropyFunction()=default
itk::HistogramToImageFilter
This class takes a histogram as an input and returns an image of type specified by the functor.
Definition: itkHistogramToImageFilter.h:50
itk::Function::HistogramEntropyFunction
Definition: itkHistogramToEntropyImageFilter.h:56
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83