ITK  5.4.0
Insight Toolkit
itkWeightedAddImageFilter.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 itkWeightedAddImageFilter_h
19 #define itkWeightedAddImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 #include "itkMath.h"
24 
25 namespace itk
26 {
27 namespace Functor
28 {
34 template <typename TInput1, typename TInput2, typename TOutput>
36 {
37 public:
41  : m_Alpha(0.0)
42  , m_Beta(0.0)
43  {}
44  ~WeightedAdd2() = default;
47  bool
48  operator==(const WeightedAdd2 & other) const
49  {
50  return Math::ExactlyEquals(m_Alpha, other.m_Alpha);
51  }
52 
54 
55  inline TOutput
56  operator()(const TInput1 & A, const TInput2 & B) const
57  {
58  const RealType sum1 = A * m_Alpha;
59  const RealType sum2 = B * m_Beta;
60 
61  return static_cast<TOutput>(sum1 + sum2);
62  }
63 
64  void
66  {
67  m_Alpha = alpha;
69  }
70 
71  RealType
72  GetAlpha() const
73  {
74  return m_Alpha;
75  }
76 
77 private:
79  RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
80 };
81 } // namespace Functor
82 
116 template <typename TInputImage1, typename TInputImage2, typename TOutputImage>
117 class ITK_TEMPLATE_EXPORT WeightedAddImageFilter
118  : public BinaryGeneratorImageFilter<TInputImage1, TInputImage2, TOutputImage>
119 
120 {
121 public:
122  ITK_DISALLOW_COPY_AND_MOVE(WeightedAddImageFilter);
123 
127 
128 
129  using FunctorType = Functor::
130  WeightedAdd2<typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType>;
131 
134 
135  using RealType = typename FunctorType::RealType;
136 
138  itkNewMacro(Self);
139 
141  itkOverrideGetNameOfClassMacro(WeightedAddImageFilter);
142 
144  void
146  {
147  this->GetFunctor().SetAlpha(alpha);
148  this->Modified();
149  }
153  RealType
154  GetAlpha() const
155  {
156  return this->GetFunctor().GetAlpha();
157  }
158 
159 #ifdef ITK_USE_CONCEPT_CHECKING
160  // Begin concept checking
162  itkConceptMacro(Input1RealTypeMultiplyCheck,
164  itkConceptMacro(Input2RealTypeMultiplyCheck,
166  // End concept checking
167 #endif
168 
169 protected:
170  WeightedAddImageFilter() = default;
171  ~WeightedAddImageFilter() override = default;
172 
173  void
175  {
176  this->SetFunctor(this->GetFunctor());
177  }
178 
179 private:
180  itkGetConstReferenceMacro(Functor, FunctorType);
181  FunctorType &
183  {
184  return m_Functor;
185  }
186 
187  FunctorType m_Functor{};
188 };
189 } // end namespace itk
190 
191 #endif
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:714
itk::Functor::WeightedAdd2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType >::AccumulatorType
typename NumericTraits< typename TInputImage1::PixelType >::AccumulateType AccumulatorType
Definition: itkWeightedAddImageFilter.h:38
itk::Functor::WeightedAdd2
Definition: itkWeightedAddImageFilter.h:35
itk::Functor::WeightedAdd2::WeightedAdd2
WeightedAdd2()
Definition: itkWeightedAddImageFilter.h:40
itk::Functor::WeightedAdd2::SetAlpha
void SetAlpha(RealType alpha)
Definition: itkWeightedAddImageFilter.h:65
itk::Math::ExactlyEquals
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:726
itk::Functor::WeightedAdd2::operator==
bool operator==(const WeightedAdd2 &other) const
Definition: itkWeightedAddImageFilter.h:48
itk::BinaryGeneratorImageFilter
Implements pixel-wise generic operation of two images, or of an image and a constant.
Definition: itkBinaryGeneratorImageFilter.h:56
itk::SmartPointer< Self >
itk::Functor::WeightedAdd2::m_Beta
RealType m_Beta
Definition: itkWeightedAddImageFilter.h:79
itk::Functor::WeightedAdd2::GetAlpha
RealType GetAlpha() const
Definition: itkWeightedAddImageFilter.h:72
itk::WeightedAddImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: itkWeightedAddImageFilter.h:174
itkBinaryGeneratorImageFilter.h
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::WeightedAdd2::~WeightedAdd2
~WeightedAdd2()=default
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:157
itk::Functor::WeightedAdd2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType >::RealType
typename NumericTraits< typename TInputImage1::PixelType >::RealType RealType
Definition: itkWeightedAddImageFilter.h:39
itk::WeightedAddImageFilter
Computes a weighted sum of two images pixel-wise.
Definition: itkWeightedAddImageFilter.h:117
itk::Functor::WeightedAdd2::m_Alpha
RealType m_Alpha
Definition: itkWeightedAddImageFilter.h:78
FunctorType
Functor::Add2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: itkAddImageFilter.h:97
itk::Functor::WeightedAdd2::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(WeightedAdd2)
itk::Concept::MultiplyOperator
Definition: itkConceptChecking.h:419
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:59
itk::WeightedAddImageFilter::GetFunctor
FunctorType & GetFunctor()
Definition: itkWeightedAddImageFilter.h:182
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::WeightedAddImageFilter::RealType
typename FunctorType::RealType RealType
Definition: itkWeightedAddImageFilter.h:135
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::WeightedAddImageFilter::SetAlpha
void SetAlpha(RealType alpha)
Definition: itkWeightedAddImageFilter.h:145
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::Functor::WeightedAdd2::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkWeightedAddImageFilter.h:56
itkNumericTraits.h
itk::WeightedAddImageFilter::GetAlpha
RealType GetAlpha() const
Definition: itkWeightedAddImageFilter.h:154
itkMath.h