ITK  5.2.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  * http://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;
45  bool
46  operator!=(const WeightedAdd2 & other) const
47  {
49  {
50  return true;
51  }
52  return false;
53  }
55 
56  bool
57  operator==(const WeightedAdd2 & other) const
58  {
59  return !(*this != other);
60  }
61 
62  inline TOutput
63  operator()(const TInput1 & A, const TInput2 & B) const
64  {
65  const RealType sum1 = A * m_Alpha;
66  const RealType sum2 = B * m_Beta;
67 
68  return static_cast<TOutput>(sum1 + sum2);
69  }
70 
71  void
73  {
74  m_Alpha = alpha;
76  }
77 
78  RealType
79  GetAlpha() const
80  {
81  return m_Alpha;
82  }
83 
84 private:
86  RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
87 };
88 } // namespace Functor
89 
123 template <typename TInputImage1, typename TInputImage2, typename TOutputImage>
124 class WeightedAddImageFilter : public BinaryGeneratorImageFilter<TInputImage1, TInputImage2, TOutputImage>
125 
126 {
127 public:
128  ITK_DISALLOW_COPY_AND_ASSIGN(WeightedAddImageFilter);
129 
133 
134 
135  using FunctorType = Functor::
136  WeightedAdd2<typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType>;
137 
140 
141  using RealType = typename FunctorType::RealType;
142 
144  itkNewMacro(Self);
145 
148 
150  void
152  {
153  this->GetFunctor().SetAlpha(alpha);
154  this->Modified();
155  }
157 
159  RealType
160  GetAlpha() const
161  {
162  return this->GetFunctor().GetAlpha();
163  }
164 
165 #ifdef ITK_USE_CONCEPT_CHECKING
166  // Begin concept checking
168  itkConceptMacro(Input1RealTypeMultiplyCheck,
170  itkConceptMacro(Input2RealTypeMultiplyCheck,
172  // End concept checking
173 #endif
174 
175 protected:
176  WeightedAddImageFilter() = default;
177  ~WeightedAddImageFilter() override = default;
178 
179  void
181  {
182  this->SetFunctor(this->GetFunctor());
183  }
184 
185 private:
186  itkGetConstReferenceMacro(Functor, FunctorType);
187  FunctorType &
189  {
190  return m_Functor;
191  }
192 
194 };
195 } // end namespace itk
196 
197 #endif
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:712
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::WeightedAddImageFilter::~WeightedAddImageFilter
~WeightedAddImageFilter() override=default
itk::Functor::WeightedAdd2::SetAlpha
void SetAlpha(RealType alpha)
Definition: itkWeightedAddImageFilter.h:72
itk::Functor::WeightedAdd2::operator==
bool operator==(const WeightedAdd2 &other) const
Definition: itkWeightedAddImageFilter.h:57
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::WeightedAddImageFilter::m_Functor
FunctorType m_Functor
Definition: itkWeightedAddImageFilter.h:193
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::Functor::WeightedAdd2::m_Beta
RealType m_Beta
Definition: itkWeightedAddImageFilter.h:86
itk::WeightedAddImageFilter::FunctorType
Functor::WeightedAdd2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: itkWeightedAddImageFilter.h:136
itk::Functor::WeightedAdd2::GetAlpha
RealType GetAlpha() const
Definition: itkWeightedAddImageFilter.h:79
itk::WeightedAddImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: itkWeightedAddImageFilter.h:180
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:156
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:124
itk::Functor::WeightedAdd2::operator!=
bool operator!=(const WeightedAdd2 &other) const
Definition: itkWeightedAddImageFilter.h:46
itk::Functor::WeightedAdd2::m_Alpha
RealType m_Alpha
Definition: itkWeightedAddImageFilter.h:85
itk::Concept::MultiplyOperator
Definition: itkConceptChecking.h:417
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::WeightedAddImageFilter::GetFunctor
FunctorType & GetFunctor()
Definition: itkWeightedAddImageFilter.h:188
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:64
itk::WeightedAddImageFilter::GetFunctor
virtual const FunctorType & GetFunctor() const
itk::WeightedAddImageFilter::RealType
typename FunctorType::RealType RealType
Definition: itkWeightedAddImageFilter.h:141
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:151
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::Functor::WeightedAdd2::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkWeightedAddImageFilter.h:63
itkNumericTraits.h
itk::WeightedAddImageFilter::GetAlpha
RealType GetAlpha() const
Definition: itkWeightedAddImageFilter.h:160
itk::Object::Modified
virtual void Modified() const
itkMath.h
itk::WeightedAddImageFilter::WeightedAddImageFilter
WeightedAddImageFilter()=default
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(const std::function< ConstRefFunctionType > &f)
Definition: itkBinaryGeneratorImageFilter.h:150