ITK  4.9.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 >
32 {
33 public:
36  {
37  m_Factor = 1.0;
38  m_Offset = 0.0;
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 
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  {
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  TOutput 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 >
137  public
138  UnaryFunctorImageFilter< TInputImage, TOutputImage,
139  Functor::IntensityLinearTransform<
140  typename TInputImage::PixelType,
141  typename TOutputImage::PixelType > >
142 {
143 public:
146  typedef UnaryFunctorImageFilter<
147  TInputImage, TOutputImage,
149  typename TInputImage::PixelType,
150  typename TOutputImage::PixelType > > Superclass;
151 
154 
155  typedef typename TOutputImage::PixelType OutputPixelType;
156  typedef typename TInputImage::PixelType InputPixelType;
158 
160  itkNewMacro(Self);
161 
163  itkTypeMacro(RescaleIntensityImageFilter,
165 
166  itkSetMacro(OutputMinimum, OutputPixelType);
167  itkSetMacro(OutputMaximum, OutputPixelType);
168  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
169  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
170 
174  itkGetConstReferenceMacro(Scale, RealType);
175  itkGetConstReferenceMacro(Shift, RealType);
177 
180  itkGetConstReferenceMacro(InputMinimum, InputPixelType);
181  itkGetConstReferenceMacro(InputMaximum, InputPixelType);
183 
185  void BeforeThreadedGenerateData() ITK_OVERRIDE;
186 
188  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
189 
190 #ifdef ITK_USE_CONCEPT_CHECKING
191  // Begin concept checking
192  itkConceptMacro( InputHasNumericTraitsCheck,
194  itkConceptMacro( OutputHasNumericTraitsCheck,
196  itkConceptMacro( RealTypeMultiplyOperatorCheck,
198  itkConceptMacro( RealTypeAdditiveOperatorsCheck,
200  // End concept checking
201 #endif
202 
203 protected:
206 
207 private:
208  RescaleIntensityImageFilter(const Self &) ITK_DELETE_FUNCTION;
209  void operator=(const Self &) ITK_DELETE_FUNCTION;
210 
213 
216 
219 };
220 } // end namespace itk
221 
222 #ifndef ITK_MANUAL_INSTANTIATION
223 #include "itkRescaleIntensityImageFilter.hxx"
224 #endif
225 
226 #endif
bool operator!=(const IntensityLinearTransform &other) const
Base class for all process objects that output image data.
bool operator==(const IntensityLinearTransform &other) const
static T max(const T &)
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:676
void BeforeThreadedGenerateData() override
Implements pixel-wise generic operation on one image.
Applies a linear transformation to the intensity levels of the input Image.
void PrintSelf(std::ostream &os, Indent indent) const override
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::IntensityLinearTransform< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
NumericTraits< InputPixelType >::RealType RealType