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 
23 namespace itk
24 {
47 namespace Function
48 {
49 template <typename TInput, typename TOutput = double>
51 {
52 public:
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 
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  void
79  {
80  m_TotalFrequency = n;
81  }
82 
85  {
86  return m_TotalFrequency;
87  }
88 
89 private:
91 };
92 } // namespace Function
93 
94 template <typename THistogram, typename TImage = Image<double, 3>>
96  : public HistogramToImageFilter<THistogram,
97  TImage,
98  Function::HistogramLogProbabilityFunction<SizeValueType, typename TImage::PixelType>>
99 {
100 public:
101  ITK_DISALLOW_COPY_AND_MOVE(HistogramToLogProbabilityImageFilter);
102 
105 
107  using Superclass =
108  HistogramToImageFilter<THistogram,
109  TImage,
111 
114 
116  itkOverrideGetNameOfClassMacro(HistogramToLogProbabilityImageFilter);
117 
119  itkNewMacro(Self);
120 
121 protected:
123  ~HistogramToLogProbabilityImageFilter() override = default;
124 };
125 } // end namespace itk
126 
127 #endif
itk::Function::HistogramLogProbabilityFunction
Definition: itkHistogramToLogProbabilityImageFilter.h:50
itkHistogramToImageFilter.h
itk::HistogramToLogProbabilityImageFilter::~HistogramToLogProbabilityImageFilter
~HistogramToLogProbabilityImageFilter() override=default
itk::SmartPointer< Self >
itk::Function::HistogramLogProbabilityFunction< SizeValueType, TImage::PixelType >::OutputPixelType
TImage::PixelType OutputPixelType
Definition: itkHistogramToLogProbabilityImageFilter.h:57
itk::Function::HistogramLogProbabilityFunction::m_TotalFrequency
SizeValueType m_TotalFrequency
Definition: itkHistogramToLogProbabilityImageFilter.h:90
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::Function::HistogramLogProbabilityFunction::operator()
OutputPixelType operator()(const TInput &A) const
Definition: itkHistogramToLogProbabilityImageFilter.h:64
itk::HistogramToLogProbabilityImageFilter::HistogramToLogProbabilityImageFilter
HistogramToLogProbabilityImageFilter()=default
itk::HistogramToLogProbabilityImageFilter
The class takes a histogram as an input and gives the log probability image as the output....
Definition: itkHistogramToLogProbabilityImageFilter.h:95
itk::Function::HistogramLogProbabilityFunction::GetTotalFrequency
SizeValueType GetTotalFrequency() const
Definition: itkHistogramToLogProbabilityImageFilter.h:84
itk::Function::HistogramLogProbabilityFunction::~HistogramLogProbabilityFunction
~HistogramLogProbabilityFunction()=default
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Function::HistogramLogProbabilityFunction::HistogramLogProbabilityFunction
HistogramLogProbabilityFunction()=default
itk::Function::HistogramLogProbabilityFunction::SetTotalFrequency
void SetTotalFrequency(SizeValueType n)
Definition: itkHistogramToLogProbabilityImageFilter.h:78
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::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86