ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkRescaleIntensityImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 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 #if defined (__GNUC__) && (__GNUC__ == 5) && (__GNUC_MINOR__ == 2) && defined(NDEBUG) && defined(__i386__)
42  m_EpsilonCompensation = static_cast<RealType>(std::numeric_limits<TOutput>::epsilon());
43  if (m_EpsilonCompensation == 0)
44  {
45  m_EpsilonCompensation = std::numeric_limits<RealType>::epsilon();
46  }
47 #endif
48  }
49 
50  ~IntensityLinearTransform() = default;
51  void SetFactor(RealType a) { m_Factor = a; }
52  void SetOffset(RealType b) { m_Offset = b; }
53  void SetMinimum(TOutput min) { m_Minimum = min; }
54  void SetMaximum(TOutput max) { m_Maximum = max; }
55  bool operator!=(const IntensityLinearTransform & other) const
56  {
57  if ( Math::NotExactlyEquals(m_Factor, other.m_Factor)
58  || Math::NotExactlyEquals(m_Offset, other.m_Offset)
59  || Math::NotExactlyEquals(m_Maximum, other.m_Maximum)
60  || Math::NotExactlyEquals(m_Minimum, other.m_Minimum) )
61  {
62  return true;
63  }
64  return false;
65  }
66 
67  bool operator==(const IntensityLinearTransform & other) const
68  {
69  return !( *this != other );
70  }
71 
72  inline TOutput operator()(const TInput & x) const
73  {
74 #if defined (__GNUC__) && (__GNUC__ == 5) && (__GNUC_MINOR__ == 2) && defined(NDEBUG) && defined(__i386__)
75  RealType value = static_cast< RealType >( x ) * m_Factor + m_Offset + m_EpsilonCompensation;
76  TOutput result = static_cast< TOutput >( value ) - static_cast< TOutput >( m_EpsilonCompensation );
77 #else
78  RealType value = static_cast< RealType >( x ) * m_Factor + m_Offset;
79  auto result = static_cast< TOutput >( value );
80 #endif
81  result = ( result > m_Maximum ) ? m_Maximum : result;
82  result = ( result < m_Minimum ) ? m_Minimum : result;
83  return result;
84  }
85 
86 private:
89  TOutput m_Maximum;
90  TOutput m_Minimum;
91 #if defined (__GNUC__) && (__GNUC__ == 5) && (__GNUC_MINOR__ == 2) && defined(NDEBUG) && defined(__i386__)
92  RealType m_EpsilonCompensation;
93 #endif
94 };
95 } // end namespace Functor
96 
135 template< typename TInputImage, typename TOutputImage = TInputImage >
136 class ITK_TEMPLATE_EXPORT RescaleIntensityImageFilter:
137  public
138  UnaryFunctorImageFilter< TInputImage, TOutputImage,
139  Functor::IntensityLinearTransform<
140  typename TInputImage::PixelType,
141  typename TOutputImage::PixelType > >
142 {
143 public:
144  ITK_DISALLOW_COPY_AND_ASSIGN(RescaleIntensityImageFilter);
145 
149  TInputImage, TOutputImage,
151  typename TInputImage::PixelType,
152  typename TOutputImage::PixelType > >;
153 
156 
157  using OutputPixelType = typename TOutputImage::PixelType;
158  using InputPixelType = typename TInputImage::PixelType;
160 
162  itkNewMacro(Self);
163 
165  itkTypeMacro(RescaleIntensityImageFilter,
167 
168  itkSetMacro(OutputMinimum, OutputPixelType);
169  itkSetMacro(OutputMaximum, OutputPixelType);
170  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
171  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
172 
176  itkGetConstReferenceMacro(Scale, RealType);
177  itkGetConstReferenceMacro(Shift, RealType);
179 
182  itkGetConstReferenceMacro(InputMinimum, InputPixelType);
183  itkGetConstReferenceMacro(InputMaximum, InputPixelType);
185 
187  void BeforeThreadedGenerateData() override;
188 
190  void PrintSelf(std::ostream & os, Indent indent) const override;
191 
192 #ifdef ITK_USE_CONCEPT_CHECKING
193  // Begin concept checking
194  itkConceptMacro( InputHasNumericTraitsCheck,
196  itkConceptMacro( OutputHasNumericTraitsCheck,
198  itkConceptMacro( RealTypeMultiplyOperatorCheck,
200  itkConceptMacro( RealTypeAdditiveOperatorsCheck,
202  // End concept checking
203 #endif
204 
205 protected:
207  ~RescaleIntensityImageFilter() override = default;
208 
209 private:
212 
215 
218 };
219 } // end namespace itk
220 
221 #ifndef ITK_MANUAL_INSTANTIATION
222 #include "itkRescaleIntensityImageFilter.hxx"
223 #endif
224 
225 #endif
Define numeric traits for std::vector.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
bool operator!=(const IntensityLinearTransform &other) const
Base class for all process objects that output image data.
bool operator==(const IntensityLinearTransform &other) const
typename TInputImage::PixelType InputPixelType
typename NumericTraits< InputPixelType >::RealType RealType
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:718
Implements pixel-wise generic operation on one image.
Applies a linear transformation to the intensity levels of the input Image.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
#define itkConceptMacro(name, concept)
typename TOutputImage::PixelType OutputPixelType