ITK  6.0.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 * https://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
23namespace itk
24{
53namespace Function
54{
55template <typename TInput, typename TOutput = double>
57{
58public:
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
66
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 {
88 }
89
92 {
93 return m_TotalFrequency;
94 }
95
96private:
98};
99} // namespace Function
100
101template <typename THistogram, typename TImage = Image<double, 3>>
103 : public HistogramToImageFilter<THistogram,
104 TImage,
105 Function::HistogramEntropyFunction<SizeValueType, typename TImage::PixelType>>
106{
107public:
108 ITK_DISALLOW_COPY_AND_MOVE(HistogramToEntropyImageFilter);
109
112
115 HistogramToImageFilter<THistogram,
116 TImage,
118
121
123 itkOverrideGetNameOfClassMacro(HistogramToEntropyImageFilter);
124
126 itkNewMacro(Self);
127
128protected:
130 ~HistogramToEntropyImageFilter() override = default;
131};
132} // end namespace itk
133
134#endif
OutputPixelType operator()(const TInput &A) const
The class takes a histogram as an input and gives the entropy image as the output....
~HistogramToEntropyImageFilter() override=default
This class takes a histogram as an input and returns an image of type specified by the functor.
Light weight base class for most itk classes.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86