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
23namespace 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.
28namespace Functor
29{
30template <typename TInput, typename TOutput>
31class ITK_TEMPLATE_EXPORT IntensityWindowingTransform
32{
33public:
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 {}
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
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
103private:
110};
111} // end namespace Functor
112
141template <typename TInputImage, typename TOutputImage = TInputImage>
142class ITK_TEMPLATE_EXPORT IntensityWindowingImageFilter
144 TInputImage,
145 TOutputImage,
146 Functor::IntensityWindowingTransform<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
147{
148public:
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
169 itkOverrideGetNameOfClassMacro(IntensityWindowingImageFilter);
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
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
220protected:
222 ~IntensityWindowingImageFilter() override = default;
223
224private:
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
typename NumericTraits< TInput >::RealType RealType
bool operator==(const IntensityWindowingTransform &other) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(IntensityWindowingTransform)
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Applies a linear transformation to the intensity levels of the input Image that are inside a user-def...
void BeforeThreadedGenerateData() override
InputPixelType GetWindow() const
typename TOutputImage::PixelType OutputPixelType
~IntensityWindowingImageFilter() override=default
typename NumericTraits< InputPixelType >::RealType RealType
InputPixelType GetLevel() const
void SetWindowLevel(const InputPixelType &window, const InputPixelType &level)
void PrintSelf(std::ostream &os, Indent indent) const override
Light weight base class for most itk classes.
Define additional traits for native types such as int or float.
Implements pixel-wise generic operation on one image.
#define itkConceptMacro(name, concept)
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:726
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....