ITK  4.9.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 >
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  {
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 >
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 
189  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
190 
191 #ifdef ITK_USE_CONCEPT_CHECKING
192  // Begin concept checking
193  itkConceptMacro( InputHasNumericTraitsCheck,
195  // End concept checking
196 #endif
197 
198 protected:
201 
202 private:
203  IntensityWindowingImageFilter(const Self &) ITK_DELETE_FUNCTION;
204  void operator=(const Self &) ITK_DELETE_FUNCTION;
205 
208 
211 
214 };
215 } // end namespace itk
216 
217 #ifndef ITK_MANUAL_INSTANTIATION
218 #include "itkIntensityWindowingImageFilter.hxx"
219 #endif
220 
221 #endif
void PrintSelf(std::ostream &os, Indent indent) const override
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:676
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.
void SetWindowLevel(const InputPixelType &window, const InputPixelType &level)
#define itkConceptMacro(name, concept)
void BeforeThreadedGenerateData(void) override
InputPixelType GetWindow() const
InputPixelType GetLevel() const
bool operator==(const IntensityWindowingTransform &other) const