ITK  4.8.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 
23 namespace itk
24 {
25 // This functor class applies a linear transformation A.x + B
26 // to input values.
27 namespace Functor
28 {
29 template< typename TInput, typename TOutput >
31 {
32 public:
35  {
36  m_Factor = 1.0;
37  m_Offset = 0.0;
40  }
41 
43  void SetFactor(RealType a) { m_Factor = a; }
44  void SetOffset(RealType b) { m_Offset = b; }
45  void SetMinimum(TOutput min) { m_Minimum = min; }
46  void SetMaximum(TOutput max) { m_Maximum = max; }
47  bool operator!=(const IntensityLinearTransform & other) const
48  {
49  if ( m_Factor != other.m_Factor
50  || m_Offset != other.m_Offset
51  || m_Maximum != other.m_Maximum
52  || m_Minimum != other.m_Minimum )
53  {
54  return true;
55  }
56  return false;
57  }
58 
59  bool operator==(const IntensityLinearTransform & other) const
60  {
61  return !( *this != other );
62  }
63 
64  inline TOutput operator()(const TInput & x) const
65  {
66  RealType value = static_cast< RealType >( x ) * m_Factor + m_Offset;
67  TOutput result = static_cast< TOutput >( value );
68 
69  result = ( result > m_Maximum ) ? m_Maximum : result;
70  result = ( result < m_Minimum ) ? m_Minimum : result;
71  return result;
72  }
73 
74 private:
77  TOutput m_Maximum;
78  TOutput m_Minimum;
79 };
80 } // end namespace functor
81 
120 template< typename TInputImage, typename TOutputImage = TInputImage >
122  public
123  UnaryFunctorImageFilter< TInputImage, TOutputImage,
124  Functor::IntensityLinearTransform<
125  typename TInputImage::PixelType,
126  typename TOutputImage::PixelType > >
127 {
128 public:
131  typedef UnaryFunctorImageFilter<
132  TInputImage, TOutputImage,
134  typename TInputImage::PixelType,
135  typename TOutputImage::PixelType > > Superclass;
136 
139 
140  typedef typename TOutputImage::PixelType OutputPixelType;
141  typedef typename TInputImage::PixelType InputPixelType;
143 
145  itkNewMacro(Self);
146 
148  itkTypeMacro(RescaleIntensityImageFilter,
150 
151  itkSetMacro(OutputMinimum, OutputPixelType);
152  itkSetMacro(OutputMaximum, OutputPixelType);
153  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
154  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
155 
159  itkGetConstReferenceMacro(Scale, RealType);
160  itkGetConstReferenceMacro(Shift, RealType);
162 
165  itkGetConstReferenceMacro(InputMinimum, InputPixelType);
166  itkGetConstReferenceMacro(InputMaximum, InputPixelType);
168 
170  void BeforeThreadedGenerateData() ITK_OVERRIDE;
171 
173  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
174 
175 #ifdef ITK_USE_CONCEPT_CHECKING
176  // Begin concept checking
177  itkConceptMacro( InputHasNumericTraitsCheck,
179  itkConceptMacro( OutputHasNumericTraitsCheck,
181  itkConceptMacro( RealTypeMultiplyOperatorCheck,
183  itkConceptMacro( RealTypeAdditiveOperatorsCheck,
185  // End concept checking
186 #endif
187 
188 protected:
191 
192 private:
193  RescaleIntensityImageFilter(const Self &); //purposely not implemented
194  void operator=(const Self &); //purposely not implemented
195 
198 
201 
204 };
205 } // end namespace itk
206 
207 #ifndef ITK_MANUAL_INSTANTIATION
208 #include "itkRescaleIntensityImageFilter.hxx"
209 #endif
210 
211 #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 &)
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