ITK  5.4.0
Insight Toolkit
itkRescaleIntensityImageFilter.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 itkRescaleIntensityImageFilter_h
19#define itkRescaleIntensityImageFilter_h
20
22#include "itkMath.h"
23
24namespace itk
25{
26// This functor class applies a linear transformation A.x + B
27// to input values.
28namespace Functor
29{
30template <typename TInput, typename TOutput>
31class ITK_TEMPLATE_EXPORT IntensityLinearTransform
32{
33public:
36 {
37 m_Factor = 1.0;
38 m_Offset = 0.0;
40 m_Maximum = NumericTraits<TOutput>::max();
41 }
42
44 void
46 {
47 m_Factor = a;
48 }
49 void
51 {
52 m_Offset = b;
53 }
54 void
55 SetMinimum(TOutput min)
56 {
57 m_Minimum = min;
58 }
59 void
60 SetMaximum(TOutput max)
61 {
62 m_Maximum = max;
63 }
64
65 bool
67 {
68 return Math::ExactlyEquals(m_Factor, other.m_Factor) && Math::ExactlyEquals(m_Offset, other.m_Offset) &&
69 Math::ExactlyEquals(m_Maximum, other.m_Maximum) && Math::ExactlyEquals(m_Minimum, other.m_Minimum);
70 }
71
73
74 inline TOutput
75 operator()(const TInput & x) const
76 {
77 RealType value = static_cast<RealType>(x) * m_Factor + m_Offset;
78 auto result = static_cast<TOutput>(value);
79
80 result = (result > m_Maximum) ? m_Maximum : result;
81 result = (result < m_Minimum) ? m_Minimum : result;
82 return result;
83 }
84
85private:
88 TOutput m_Maximum;
89 TOutput m_Minimum;
90};
91} // end namespace Functor
92
132template <typename TInputImage, typename TOutputImage = TInputImage>
133class ITK_TEMPLATE_EXPORT RescaleIntensityImageFilter
135 TInputImage,
136 TOutputImage,
137 Functor::IntensityLinearTransform<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
138{
139public:
140 ITK_DISALLOW_COPY_AND_MOVE(RescaleIntensityImageFilter);
146 TInputImage,
147 TOutputImage,
149
152
153 using OutputPixelType = typename TOutputImage::PixelType;
154 using InputPixelType = typename TInputImage::PixelType;
156
158 itkNewMacro(Self);
159
161 itkOverrideGetNameOfClassMacro(RescaleIntensityImageFilter);
162
163 itkSetMacro(OutputMinimum, OutputPixelType);
164 itkSetMacro(OutputMaximum, OutputPixelType);
165 itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
166 itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
167
171 itkGetConstReferenceMacro(Scale, RealType);
172 itkGetConstReferenceMacro(Shift, RealType);
177 itkGetConstReferenceMacro(InputMinimum, InputPixelType);
178 itkGetConstReferenceMacro(InputMaximum, InputPixelType);
182 void
184
186 void
187 PrintSelf(std::ostream & os, Indent indent) const override;
188
189#ifdef ITK_USE_CONCEPT_CHECKING
190 // Begin concept checking
191 itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
192 itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputPixelType>));
193 itkConceptMacro(RealTypeMultiplyOperatorCheck, (Concept::MultiplyOperator<RealType>));
194 itkConceptMacro(RealTypeAdditiveOperatorsCheck, (Concept::AdditiveOperators<RealType>));
195 // End concept checking
196#endif
197
198protected:
200 ~RescaleIntensityImageFilter() override = default;
201
202private:
203 RealType m_Scale{};
204 RealType m_Shift{};
205
206 InputPixelType m_InputMinimum{};
207 InputPixelType m_InputMaximum{};
208
209 OutputPixelType m_OutputMinimum{};
210 OutputPixelType m_OutputMaximum{};
211};
212} // end namespace itk
213
214#ifndef ITK_MANUAL_INSTANTIATION
215# include "itkRescaleIntensityImageFilter.hxx"
216#endif
217
218#endif
typename NumericTraits< TInput >::RealType RealType
bool operator==(const IntensityLinearTransform &other) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(IntensityLinearTransform)
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Define additional traits for native types such as int or float.
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
Applies a linear transformation to the intensity levels of the input Image.
typename NumericTraits< InputPixelType >::RealType RealType
typename TInputImage::PixelType InputPixelType
void PrintSelf(std::ostream &os, Indent indent) const override
~RescaleIntensityImageFilter() override=default
void BeforeThreadedGenerateData() override
typename TOutputImage::PixelType OutputPixelType
Implements pixel-wise generic operation on one image.
#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....