ITK  5.4.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  * https://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 
45  bool
47  {
48  return Math::ExactlyEquals(m_Factor, other.m_Factor) && Math::ExactlyEquals(m_Offset, other.m_Offset) &&
49  Math::ExactlyEquals(m_OutputMaximum, other.m_OutputMaximum) &&
50  Math::ExactlyEquals(m_OutputMinimum, other.m_OutputMinimum) &&
51  Math::ExactlyEquals(m_WindowMaximum, other.m_WindowMaximum) &&
52  Math::ExactlyEquals(m_WindowMinimum, other.m_WindowMinimum);
53  }
54 
55  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(IntensityWindowingTransform);
56 
57  void
59  {
60  m_Factor = a;
61  }
62  void
64  {
65  m_Offset = b;
66  }
67  void
68  SetOutputMinimum(TOutput min)
69  {
70  m_OutputMinimum = min;
71  }
72  void
73  SetOutputMaximum(TOutput max)
74  {
75  m_OutputMaximum = max;
76  }
77  void
78  SetWindowMinimum(TInput min)
79  {
80  m_WindowMinimum = min;
81  }
82  void
83  SetWindowMaximum(TInput max)
84  {
85  m_WindowMaximum = max;
86  }
87  inline TOutput
88  operator()(const TInput & x) const
89  {
90  if (x < m_WindowMinimum)
91  {
92  return m_OutputMinimum;
93  }
94  if (x > m_WindowMaximum)
95  {
96  return m_OutputMaximum;
97  }
98  const RealType value = static_cast<RealType>(x) * m_Factor + m_Offset;
99  const auto result = static_cast<TOutput>(value);
100  return result;
101  }
102 
103 private:
110 };
111 } // end namespace Functor
112 
141 template <typename TInputImage, typename TOutputImage = TInputImage>
142 class ITK_TEMPLATE_EXPORT IntensityWindowingImageFilter
143  : public UnaryFunctorImageFilter<
144  TInputImage,
145  TOutputImage,
146  Functor::IntensityWindowingTransform<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
147 {
148 public:
149  ITK_DISALLOW_COPY_AND_MOVE(IntensityWindowingImageFilter);
150 
154  TInputImage,
155  TOutputImage,
157 
160 
161  using OutputPixelType = typename TOutputImage::PixelType;
162  using InputPixelType = typename TInputImage::PixelType;
164 
166  itkNewMacro(Self);
167 
170 
173  itkSetMacro(OutputMinimum, OutputPixelType);
174  itkSetMacro(OutputMaximum, OutputPixelType);
175  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
176  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
181  itkSetMacro(WindowMinimum, InputPixelType);
182  itkSetMacro(WindowMaximum, InputPixelType);
183  itkGetConstReferenceMacro(WindowMinimum, InputPixelType);
184  itkGetConstReferenceMacro(WindowMaximum, InputPixelType);
191  void
192  SetWindowLevel(const InputPixelType & window, const InputPixelType & level);
193 
195  GetWindow() const;
196 
198  GetLevel() const;
199 
203  itkGetConstReferenceMacro(Scale, RealType);
204  itkGetConstReferenceMacro(Shift, RealType);
208  void
209  BeforeThreadedGenerateData() override;
210 
211  void
212  PrintSelf(std::ostream & os, Indent indent) const override;
213 
214 #ifdef ITK_USE_CONCEPT_CHECKING
215  // Begin concept checking
216  itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
217  // End concept checking
218 #endif
219 
220 protected:
222  ~IntensityWindowingImageFilter() override = default;
223 
224 private:
225  RealType m_Scale{};
226  RealType m_Shift{};
227 
228  InputPixelType m_WindowMinimum{};
229  InputPixelType m_WindowMaximum{};
230 
231  OutputPixelType m_OutputMinimum{};
232  OutputPixelType m_OutputMaximum{};
233 };
234 } // end namespace itk
235 
236 #ifndef ITK_MANUAL_INSTANTIATION
237 # include "itkIntensityWindowingImageFilter.hxx"
238 #endif
239 
240 #endif
itkUnaryFunctorImageFilter.h
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:714
itk::Functor::IntensityWindowingTransform::SetWindowMaximum
void SetWindowMaximum(TInput max)
Definition: itkIntensityWindowingImageFilter.h:83
itk::IntensityWindowingImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkIntensityWindowingImageFilter.h:162
itk::Functor::IntensityWindowingTransform::SetWindowMinimum
void SetWindowMinimum(TInput min)
Definition: itkIntensityWindowingImageFilter.h:78
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:46
itk::Functor::IntensityWindowingTransform
Definition: itkIntensityWindowingImageFilter.h:31
itk::Functor::IntensityWindowingTransform::m_Factor
RealType m_Factor
Definition: itkIntensityWindowingImageFilter.h:104
itk::Math::ExactlyEquals
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:728
itk::IntensityWindowingImageFilter::RealType
typename NumericTraits< InputPixelType >::RealType RealType
Definition: itkIntensityWindowingImageFilter.h:163
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:161
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Functor::IntensityWindowingTransform::m_OutputMinimum
TOutput m_OutputMinimum
Definition: itkIntensityWindowingImageFilter.h:107
itk::Functor::IntensityWindowingTransform::m_OutputMaximum
TOutput m_OutputMaximum
Definition: itkIntensityWindowingImageFilter.h:106
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:73
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:142
itk::Functor::IntensityWindowingTransform::SetOutputMinimum
void SetOutputMinimum(TOutput min)
Definition: itkIntensityWindowingImageFilter.h:68
itk::Functor::IntensityWindowingTransform::m_WindowMinimum
TInput m_WindowMinimum
Definition: itkIntensityWindowingImageFilter.h:109
itk::Functor::IntensityWindowingTransform::operator()
TOutput operator()(const TInput &x) const
Definition: itkIntensityWindowingImageFilter.h:88
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:59
itk::Functor::IntensityWindowingTransform::SetOffset
void SetOffset(RealType b)
Definition: itkIntensityWindowingImageFilter.h:63
itk::Functor::IntensityWindowingTransform::m_WindowMaximum
TInput m_WindowMaximum
Definition: itkIntensityWindowingImageFilter.h:108
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:139
itk::Functor::IntensityWindowingTransform::m_Offset
RealType m_Offset
Definition: itkIntensityWindowingImageFilter.h:105
itk::Functor::IntensityWindowingTransform::SetFactor
void SetFactor(RealType a)
Definition: itkIntensityWindowingImageFilter.h:58