ITK  5.0.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) {}
42  ~IntensityWindowingTransform() = default;
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 auto 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:
129  ITK_DISALLOW_COPY_AND_ASSIGN(IntensityWindowingImageFilter);
130 
134  TInputImage, TOutputImage,
136  typename TInputImage::PixelType,
137  typename TOutputImage::PixelType > >;
138 
141 
142  using OutputPixelType = typename TOutputImage::PixelType;
143  using InputPixelType = typename TInputImage::PixelType;
145 
147  itkNewMacro(Self);
148 
150  itkTypeMacro(IntensityWindowingImageFilter,
152 
155  itkSetMacro(OutputMinimum, OutputPixelType);
156  itkSetMacro(OutputMaximum, OutputPixelType);
157  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
158  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
160 
163  itkSetMacro(WindowMinimum, InputPixelType);
164  itkSetMacro(WindowMaximum, InputPixelType);
165  itkGetConstReferenceMacro(WindowMinimum, InputPixelType);
166  itkGetConstReferenceMacro(WindowMaximum, InputPixelType);
168 
173  void SetWindowLevel(const InputPixelType & window,
174  const InputPixelType & level);
175 
176  InputPixelType GetWindow() const;
177 
178  InputPixelType GetLevel() const;
179 
183  itkGetConstReferenceMacro(Scale, RealType);
184  itkGetConstReferenceMacro(Shift, RealType);
186 
188  void BeforeThreadedGenerateData() override;
189 
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  // End concept checking
197 #endif
198 
199 protected:
201  ~IntensityWindowingImageFilter() override = default;
202 
203 private:
206 
209 
212 };
213 } // end namespace itk
214 
215 #ifndef ITK_MANUAL_INSTANTIATION
216 #include "itkIntensityWindowingImageFilter.hxx"
217 #endif
218 
219 #endif
Define numeric traits for std::vector.
typename NumericTraits< InputPixelType >::RealType RealType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
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...
typename TOutputImage::PixelType OutputPixelType
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:718
Implements pixel-wise generic operation on one image.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
#define itkConceptMacro(name, concept)
bool operator==(const IntensityWindowingTransform &other) const