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  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  {
81  m_TotalFrequency = n;
82  }
83 
86  {
87  return m_TotalFrequency;
88  }
89 
90 private:
92 };
93 } // namespace Function
94 
95 template <typename THistogram, typename TImage = Image<double, 3>>
97  : public HistogramToImageFilter<THistogram,
98  TImage,
99  Function::HistogramLogProbabilityFunction<SizeValueType, typename TImage::PixelType>>
100 {
101 public:
102  ITK_DISALLOW_COPY_AND_MOVE(HistogramToLogProbabilityImageFilter);
103 
106 
108  using Superclass =
109  HistogramToImageFilter<THistogram,
110  TImage,
112 
115 
117  itkOverrideGetNameOfClassMacro(HistogramToLogProbabilityImageFilter);
118 
120  itkNewMacro(Self);
121 
122 protected:
124  ~HistogramToLogProbabilityImageFilter() override = default;
125 };
126 } // end namespace itk
127 
128 #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:91
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:96
itk::Function::HistogramLogProbabilityFunction::GetTotalFrequency
SizeValueType GetTotalFrequency() const
Definition: itkHistogramToLogProbabilityImageFilter.h:85
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:79
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