ITK  6.0.0
Insight Toolkit
itkHistogramToLogProbabilityImageFilter.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 itkHistogramToLogProbabilityImageFilter_h
19#define itkHistogramToLogProbabilityImageFilter_h
20
22
23namespace itk
24{
47namespace Function
48{
49template <typename TInput, typename TOutput = double>
51{
52public:
53 // Probability function = Number of occurrences in each bin /
54 // Total Number of occurrences.
55 //
56 // Returns pixels of float..
57 using OutputPixelType = TOutput;
58
60
62
63 inline OutputPixelType
64 operator()(const TInput & A) const
65 {
66 if (A)
67 {
68 return static_cast<OutputPixelType>(
69 std::log(static_cast<OutputPixelType>(A) / static_cast<OutputPixelType>(m_TotalFrequency)) / std::log(2.0));
70 }
71 else
72 { // Check for Log 0. Always assume that the frequency is at least 1.
73 return static_cast<OutputPixelType>(
74 std::log(static_cast<OutputPixelType>(A + 1) / static_cast<OutputPixelType>(m_TotalFrequency)) / std::log(2.0));
75 }
76 }
77
78 void
80 {
82 }
83
86 {
87 return m_TotalFrequency;
88 }
89
90private:
92};
93} // namespace Function
94
95template <typename THistogram, typename TImage = Image<double, 3>>
97 : public HistogramToImageFilter<THistogram,
98 TImage,
99 Function::HistogramLogProbabilityFunction<SizeValueType, typename TImage::PixelType>>
100{
101public:
102 ITK_DISALLOW_COPY_AND_MOVE(HistogramToLogProbabilityImageFilter);
103
106
109 HistogramToImageFilter<THistogram,
110 TImage,
112
115
117 itkOverrideGetNameOfClassMacro(HistogramToLogProbabilityImageFilter);
118
120 itkNewMacro(Self);
121
122protected:
125};
126} // end namespace itk
127
128#endif
This class takes a histogram as an input and returns an image of type specified by the functor.
The class takes a histogram as an input and gives the log probability image as the output....
~HistogramToLogProbabilityImageFilter() override=default
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