ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkIntensityWindowingImageFilter.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 itkIntensityWindowingImageFilter_h
19 #define itkIntensityWindowingImageFilter_h
20 
22 
23 namespace itk
24 {
25 // This functor class applies a linear transformation A.x + B inside a specified
26 // range. Values below the range are mapped to a constant. Values over the range
27 // are mapped to another constant.
28 namespace Functor
29 {
30 template< typename TInput, typename TOutput >
31 class ITK_TEMPLATE_EXPORT IntensityWindowingTransform
32 {
33 public:
36  m_Factor(0.0),
37  m_Offset(0.0),
38  m_OutputMaximum(0),
39  m_OutputMinimum(0),
40  m_WindowMaximum(0),
41  m_WindowMinimum(0) {}
43  bool operator!=(const IntensityWindowingTransform & other) const
44  {
45  if ( Math::NotExactlyEquals( m_Factor , other.m_Factor )
46  || Math::NotExactlyEquals( m_Offset , other.m_Offset )
47  || Math::NotExactlyEquals( m_OutputMaximum, other.m_OutputMaximum )
48  || Math::NotExactlyEquals( m_OutputMinimum, other.m_OutputMinimum )
49  || Math::NotExactlyEquals( m_WindowMaximum, other.m_WindowMaximum )
50  || Math::NotExactlyEquals( m_WindowMinimum, other.m_WindowMinimum ) )
51  {
52  return true;
53  }
54  return false;
55  }
56 
57  bool operator==(const IntensityWindowingTransform & other) const
58  {
59  return !( *this != other );
60  }
61 
62  void SetFactor(RealType a) { m_Factor = a; }
63  void SetOffset(RealType b) { m_Offset = b; }
64  void SetOutputMinimum(TOutput min) { m_OutputMinimum = min; }
65  void SetOutputMaximum(TOutput max) { m_OutputMaximum = max; }
66  void SetWindowMinimum(TInput min) { m_WindowMinimum = min; }
67  void SetWindowMaximum(TInput max) { m_WindowMaximum = max; }
68  inline TOutput operator()(const TInput & x) const
69  {
70  if ( x < m_WindowMinimum )
71  {
72  return m_OutputMinimum;
73  }
74  if ( x > m_WindowMaximum )
75  {
76  return m_OutputMaximum;
77  }
78  const RealType value = static_cast< RealType >( x ) * m_Factor + m_Offset;
79  const TOutput result = static_cast< TOutput >( value );
80  return result;
81  }
82 
83 private:
86  TOutput m_OutputMaximum;
87  TOutput m_OutputMinimum;
90 };
91 } // end namespace functor
92 
120 template< typename TInputImage, typename TOutputImage = TInputImage >
121 class ITK_TEMPLATE_EXPORT IntensityWindowingImageFilter:
122  public
123  UnaryFunctorImageFilter< TInputImage, TOutputImage,
124  Functor::IntensityWindowingTransform<
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(IntensityWindowingImageFilter,
150 
153  itkSetMacro(OutputMinimum, OutputPixelType);
154  itkSetMacro(OutputMaximum, OutputPixelType);
155  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
156  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
158 
161  itkSetMacro(WindowMinimum, InputPixelType);
162  itkSetMacro(WindowMaximum, InputPixelType);
163  itkGetConstReferenceMacro(WindowMinimum, InputPixelType);
164  itkGetConstReferenceMacro(WindowMaximum, InputPixelType);
166 
171  void SetWindowLevel(const InputPixelType & window,
172  const InputPixelType & level);
173 
174  InputPixelType GetWindow() const;
175 
176  InputPixelType GetLevel() const;
177 
181  itkGetConstReferenceMacro(Scale, RealType);
182  itkGetConstReferenceMacro(Shift, RealType);
184 
186  void BeforeThreadedGenerateData(void) ITK_OVERRIDE;
187 
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  // End concept checking
195 #endif
196 
197 protected:
199  virtual ~IntensityWindowingImageFilter() ITK_OVERRIDE {}
200 
201 private:
202  ITK_DISALLOW_COPY_AND_ASSIGN(IntensityWindowingImageFilter);
203 
206 
209 
212 };
213 } // end namespace itk
214 
215 #ifndef ITK_MANUAL_INSTANTIATION
216 #include "itkIntensityWindowingImageFilter.hxx"
217 #endif
218 
219 #endif
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::IntensityWindowingTransform< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
NumericTraits< InputPixelType >::RealType RealType
Base class for all process objects that output image data.
bool operator!=(const IntensityWindowingTransform &other) const
Applies a linear transformation to the intensity levels of the input Image that are inside a user-def...
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:721
Implements pixel-wise generic operation on one image.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
bool operator==(const IntensityWindowingTransform &other) const