ITK  6.0.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 
24 namespace itk
25 {
26 // This functor class applies a linear transformation A.x + B
27 // to input values.
28 namespace Functor
29 {
30 template <typename TInput, typename TOutput>
31 class ITK_TEMPLATE_EXPORT IntensityLinearTransform
32 {
33 public:
36  {
37  m_Factor = 1.0;
38  m_Offset = 0.0;
40  m_Maximum = NumericTraits<TOutput>::max();
41  }
42 
43  ~IntensityLinearTransform() = default;
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
66  operator==(const IntensityLinearTransform & other) const
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 
72  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(IntensityLinearTransform);
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 
85 private:
88  TOutput m_Maximum;
89  TOutput m_Minimum;
90 };
91 } // end namespace Functor
92 
132 template <typename TInputImage, typename TOutputImage = TInputImage>
133 class ITK_TEMPLATE_EXPORT RescaleIntensityImageFilter
134  : public UnaryFunctorImageFilter<
135  TInputImage,
136  TOutputImage,
137  Functor::IntensityLinearTransform<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
138 {
139 public:
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
183  BeforeThreadedGenerateData() override;
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 
198 protected:
200  ~RescaleIntensityImageFilter() override = default;
201 
202 private:
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
itk::Functor::IntensityLinearTransform::m_Factor
RealType m_Factor
Definition: itkRescaleIntensityImageFilter.h:86
itkUnaryFunctorImageFilter.h
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:716
itk::RescaleIntensityImageFilter::RealType
typename NumericTraits< InputPixelType >::RealType RealType
Definition: itkRescaleIntensityImageFilter.h:155
itk::Functor::IntensityLinearTransform::operator==
bool operator==(const IntensityLinearTransform &other) const
Definition: itkRescaleIntensityImageFilter.h:66
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:99
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:722
itk::SmartPointer< Self >
itk::Functor::IntensityLinearTransform::SetMinimum
void SetMinimum(TOutput min)
Definition: itkRescaleIntensityImageFilter.h:55
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Functor::IntensityLinearTransform::m_Offset
RealType m_Offset
Definition: itkRescaleIntensityImageFilter.h:87
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::IntensityLinearTransform::SetFactor
void SetFactor(RealType a)
Definition: itkRescaleIntensityImageFilter.h:45
itk::RescaleIntensityImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkRescaleIntensityImageFilter.h:153
itk::Functor::IntensityLinearTransform::IntensityLinearTransform
IntensityLinearTransform()
Definition: itkRescaleIntensityImageFilter.h:35
itk::Functor::IntensityLinearTransform::SetOffset
void SetOffset(RealType b)
Definition: itkRescaleIntensityImageFilter.h:50
itk::Functor::IntensityLinearTransform::operator()
TOutput operator()(const TInput &x) const
Definition: itkRescaleIntensityImageFilter.h:75
itk::Concept::MultiplyOperator
Definition: itkConceptChecking.h:421
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:169
itk::Concept::AdditiveOperators
Definition: itkConceptChecking.h:360
itk::Functor::IntensityLinearTransform
Definition: itkRescaleIntensityImageFilter.h:31
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::RescaleIntensityImageFilter
Applies a linear transformation to the intensity levels of the input Image.
Definition: itkRescaleIntensityImageFilter.h:133
itk::Functor::IntensityLinearTransform::SetMaximum
void SetMaximum(TOutput max)
Definition: itkRescaleIntensityImageFilter.h:60
itk::Functor::IntensityLinearTransform::m_Maximum
TOutput m_Maximum
Definition: itkRescaleIntensityImageFilter.h:88
itk::Functor::IntensityLinearTransform< TInputImage::PixelType, TOutputImage::PixelType >::RealType
typename NumericTraits< TInputImage::PixelType >::RealType RealType
Definition: itkRescaleIntensityImageFilter.h:34
itk::RescaleIntensityImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkRescaleIntensityImageFilter.h:154
itk::Functor::IntensityLinearTransform::m_Minimum
TOutput m_Minimum
Definition: itkRescaleIntensityImageFilter.h:89
itkMath.h