ITK  5.2.0
Insight Toolkit
itkIntensityWindowingImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  {}
43  ~IntensityWindowingTransform() = default;
44  bool
46  {
47  if (Math::NotExactlyEquals(m_Factor, other.m_Factor) || Math::NotExactlyEquals(m_Offset, other.m_Offset) ||
48  Math::NotExactlyEquals(m_OutputMaximum, other.m_OutputMaximum) ||
49  Math::NotExactlyEquals(m_OutputMinimum, other.m_OutputMinimum) ||
50  Math::NotExactlyEquals(m_WindowMaximum, other.m_WindowMaximum) ||
51  Math::NotExactlyEquals(m_WindowMinimum, other.m_WindowMinimum))
52  {
53  return true;
54  }
55  return false;
56  }
57 
58  bool
60  {
61  return !(*this != other);
62  }
63 
64  void
66  {
67  m_Factor = a;
68  }
69  void
71  {
72  m_Offset = b;
73  }
74  void
75  SetOutputMinimum(TOutput min)
76  {
77  m_OutputMinimum = min;
78  }
79  void
80  SetOutputMaximum(TOutput max)
81  {
82  m_OutputMaximum = max;
83  }
84  void
85  SetWindowMinimum(TInput min)
86  {
87  m_WindowMinimum = min;
88  }
89  void
90  SetWindowMaximum(TInput max)
91  {
92  m_WindowMaximum = max;
93  }
94  inline TOutput
95  operator()(const TInput & x) const
96  {
97  if (x < m_WindowMinimum)
98  {
99  return m_OutputMinimum;
100  }
101  if (x > m_WindowMaximum)
102  {
103  return m_OutputMaximum;
104  }
105  const RealType value = static_cast<RealType>(x) * m_Factor + m_Offset;
106  const auto result = static_cast<TOutput>(value);
107  return result;
108  }
109 
110 private:
117 };
118 } // end namespace Functor
119 
148 template <typename TInputImage, typename TOutputImage = TInputImage>
149 class ITK_TEMPLATE_EXPORT IntensityWindowingImageFilter
150  : public UnaryFunctorImageFilter<
151  TInputImage,
152  TOutputImage,
153  Functor::IntensityWindowingTransform<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
154 {
155 public:
156  ITK_DISALLOW_COPY_AND_MOVE(IntensityWindowingImageFilter);
157 
161  TInputImage,
162  TOutputImage,
164 
167 
168  using OutputPixelType = typename TOutputImage::PixelType;
169  using InputPixelType = typename TInputImage::PixelType;
171 
173  itkNewMacro(Self);
174 
177 
180  itkSetMacro(OutputMinimum, OutputPixelType);
181  itkSetMacro(OutputMaximum, OutputPixelType);
182  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
183  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
185 
188  itkSetMacro(WindowMinimum, InputPixelType);
189  itkSetMacro(WindowMaximum, InputPixelType);
190  itkGetConstReferenceMacro(WindowMinimum, InputPixelType);
191  itkGetConstReferenceMacro(WindowMaximum, InputPixelType);
193 
198  void
199  SetWindowLevel(const InputPixelType & window, const InputPixelType & level);
200 
202  GetWindow() const;
203 
205  GetLevel() const;
206 
210  itkGetConstReferenceMacro(Scale, RealType);
211  itkGetConstReferenceMacro(Shift, RealType);
213 
215  void
216  BeforeThreadedGenerateData() override;
217 
218  void
219  PrintSelf(std::ostream & os, Indent indent) const override;
220 
221 #ifdef ITK_USE_CONCEPT_CHECKING
222  // Begin concept checking
223  itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
224  // End concept checking
225 #endif
226 
227 protected:
229  ~IntensityWindowingImageFilter() override = default;
230 
231 private:
234 
237 
240 };
241 } // end namespace itk
242 
243 #ifndef ITK_MANUAL_INSTANTIATION
244 # include "itkIntensityWindowingImageFilter.hxx"
245 #endif
246 
247 #endif
itkUnaryFunctorImageFilter.h
itk::IntensityWindowingImageFilter::m_OutputMinimum
OutputPixelType m_OutputMinimum
Definition: itkIntensityWindowingImageFilter.h:238
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:714
itk::Functor::IntensityWindowingTransform::SetWindowMaximum
void SetWindowMaximum(TInput max)
Definition: itkIntensityWindowingImageFilter.h:90
itk::IntensityWindowingImageFilter::m_OutputMaximum
OutputPixelType m_OutputMaximum
Definition: itkIntensityWindowingImageFilter.h:239
itk::IntensityWindowingImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkIntensityWindowingImageFilter.h:169
itk::Functor::IntensityWindowingTransform::SetWindowMinimum
void SetWindowMinimum(TInput min)
Definition: itkIntensityWindowingImageFilter.h:85
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::Functor::IntensityWindowingTransform::operator==
bool operator==(const IntensityWindowingTransform &other) const
Definition: itkIntensityWindowingImageFilter.h:59
itk::Functor::IntensityWindowingTransform
Definition: itkIntensityWindowingImageFilter.h:31
itk::Functor::IntensityWindowingTransform::m_Factor
RealType m_Factor
Definition: itkIntensityWindowingImageFilter.h:111
itk::IntensityWindowingImageFilter::RealType
typename NumericTraits< InputPixelType >::RealType RealType
Definition: itkIntensityWindowingImageFilter.h:170
itk::Functor::IntensityWindowingTransform< TInputImage::PixelType, TOutputImage::PixelType >::RealType
typename NumericTraits< TInputImage::PixelType >::RealType RealType
Definition: itkIntensityWindowingImageFilter.h:34
itk::IntensityWindowingImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkIntensityWindowingImageFilter.h:168
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::Functor::IntensityWindowingTransform::m_OutputMinimum
TOutput m_OutputMinimum
Definition: itkIntensityWindowingImageFilter.h:114
itk::Functor::IntensityWindowingTransform::m_OutputMaximum
TOutput m_OutputMaximum
Definition: itkIntensityWindowingImageFilter.h:113
itk::IntensityWindowingImageFilter::m_WindowMaximum
InputPixelType m_WindowMaximum
Definition: itkIntensityWindowingImageFilter.h:236
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::IntensityWindowingTransform::SetOutputMaximum
void SetOutputMaximum(TOutput max)
Definition: itkIntensityWindowingImageFilter.h:80
itk::IntensityWindowingImageFilter::m_Scale
RealType m_Scale
Definition: itkIntensityWindowingImageFilter.h:232
itk::Functor::IntensityWindowingTransform::IntensityWindowingTransform
IntensityWindowingTransform()
Definition: itkIntensityWindowingImageFilter.h:35
itk::IntensityWindowingImageFilter
Applies a linear transformation to the intensity levels of the input Image that are inside a user-def...
Definition: itkIntensityWindowingImageFilter.h:149
itk::Functor::IntensityWindowingTransform::SetOutputMinimum
void SetOutputMinimum(TOutput min)
Definition: itkIntensityWindowingImageFilter.h:75
itk::Functor::IntensityWindowingTransform::m_WindowMinimum
TInput m_WindowMinimum
Definition: itkIntensityWindowingImageFilter.h:116
itk::Functor::IntensityWindowingTransform::operator()
TOutput operator()(const TInput &x) const
Definition: itkIntensityWindowingImageFilter.h:95
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::Functor::IntensityWindowingTransform::SetOffset
void SetOffset(RealType b)
Definition: itkIntensityWindowingImageFilter.h:70
itk::IntensityWindowingImageFilter::m_WindowMinimum
InputPixelType m_WindowMinimum
Definition: itkIntensityWindowingImageFilter.h:235
itk::Functor::IntensityWindowingTransform::m_WindowMaximum
TInput m_WindowMaximum
Definition: itkIntensityWindowingImageFilter.h:115
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::Functor::IntensityWindowingTransform::m_Offset
RealType m_Offset
Definition: itkIntensityWindowingImageFilter.h:112
itk::Functor::IntensityWindowingTransform::operator!=
bool operator!=(const IntensityWindowingTransform &other) const
Definition: itkIntensityWindowingImageFilter.h:45
itk::Functor::IntensityWindowingTransform::SetFactor
void SetFactor(RealType a)
Definition: itkIntensityWindowingImageFilter.h:65
itk::IntensityWindowingImageFilter::m_Shift
RealType m_Shift
Definition: itkIntensityWindowingImageFilter.h:233