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
25namespace itk
26{
27namespace Functor
28{
34template <typename TInput1, typename TInput2, typename TOutput>
36{
37public:
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
72 GetAlpha() const
73 {
74 return m_Alpha;
75 }
76
77private:
79 RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
80};
81} // namespace Functor
82
116template <typename TInputImage1, typename TInputImage2, typename TOutputImage>
117class ITK_TEMPLATE_EXPORT WeightedAddImageFilter
118 : public BinaryGeneratorImageFilter<TInputImage1, TInputImage2, TOutputImage>
119
120{
121public:
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
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
169protected:
171 ~WeightedAddImageFilter() override = default;
172
173 void
175 {
176 this->SetFunctor(this->GetFunctor());
177 }
178
179private:
180 itkGetConstReferenceMacro(Functor, FunctorType);
183 {
184 return m_Functor;
185 }
186
187 FunctorType m_Functor{};
188};
189} // end namespace itk
190
191#endif
Implements pixel-wise generic operation of two images, or of an image and a constant.
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(WeightedAdd2)
bool operator==(const WeightedAdd2 &other) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
typename NumericTraits< TInput1 >::RealType RealType
typename NumericTraits< TInput1 >::AccumulateType AccumulatorType
Base class for all process objects that output image data.
Define additional traits for native types such as int or float.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Computes a weighted sum of two images pixel-wise.
~WeightedAddImageFilter() override=default
typename FunctorType::RealType RealType
#define itkConceptMacro(name, concept)
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
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....