ITK  4.4.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:
37  bool operator!=(const IntensityWindowingTransform & other) const
38  {
39  if ( m_Factor != other.m_Factor
40  || m_Offset != other.m_Offset
44  || m_WindowMinimum != other.m_WindowMinimum )
45  {
46  return true;
47  }
48  return false;
49  }
50 
51  bool operator==(const IntensityWindowingTransform & other) const
52  {
53  return !( *this != other );
54  }
55 
56  void SetFactor(RealType a) { m_Factor = a; }
57  void SetOffset(RealType b) { m_Offset = b; }
58  void SetOutputMinimum(TOutput min) { m_OutputMinimum = min; }
59  void SetOutputMaximum(TOutput max) { m_OutputMaximum = max; }
60  void SetWindowMinimum(TInput min) { m_WindowMinimum = min; }
61  void SetWindowMaximum(TInput max) { m_WindowMaximum = max; }
62  inline TOutput operator()(const TInput & x) const
63  {
64  if ( x < m_WindowMinimum )
65  {
66  return m_OutputMinimum;
67  }
68  if ( x > m_WindowMaximum )
69  {
70  return m_OutputMaximum;
71  }
72  const RealType value = static_cast< RealType >( x ) * m_Factor + m_Offset;
73  const TOutput result = static_cast< TOutput >( value );
74  return result;
75  }
76 
77 private:
80  TOutput m_OutputMaximum;
81  TOutput m_OutputMinimum;
84 };
85 } // end namespace functor
86 
114 template< typename TInputImage, typename TOutputImage = TInputImage >
116  public
117  UnaryFunctorImageFilter< TInputImage, TOutputImage,
118  Functor::IntensityWindowingTransform<
119  typename TInputImage::PixelType,
120  typename TOutputImage::PixelType > >
121 {
122 public:
125  typedef UnaryFunctorImageFilter<
126  TInputImage, TOutputImage,
128  typename TInputImage::PixelType,
129  typename TOutputImage::PixelType > > Superclass;
130 
133 
134  typedef typename TOutputImage::PixelType OutputPixelType;
135  typedef typename TInputImage::PixelType InputPixelType;
137 
139  itkNewMacro(Self);
140 
142  itkTypeMacro(IntensityWindowingImageFilter,
144 
147  itkSetMacro(OutputMinimum, OutputPixelType);
148  itkSetMacro(OutputMaximum, OutputPixelType);
149  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
150  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
152 
155  itkSetMacro(WindowMinimum, InputPixelType);
156  itkSetMacro(WindowMaximum, InputPixelType);
157  itkGetConstReferenceMacro(WindowMinimum, InputPixelType);
158  itkGetConstReferenceMacro(WindowMaximum, InputPixelType);
160 
165  void SetWindowLevel(const InputPixelType & window,
166  const InputPixelType & level);
167 
168  InputPixelType GetWindow() const;
169 
170  InputPixelType GetLevel() const;
171 
175  itkGetConstReferenceMacro(Scale, RealType);
176  itkGetConstReferenceMacro(Shift, RealType);
178 
180  void BeforeThreadedGenerateData(void);
181 
183  void PrintSelf(std::ostream & os, Indent indent) const;
184 
185 #ifdef ITK_USE_CONCEPT_CHECKING
186 
187  itkConceptMacro( InputHasNumericTraitsCheck,
189 
191 #endif
192 
193 protected:
196 
197 private:
198  IntensityWindowingImageFilter(const Self &); //purposely not implemented
199  void operator=(const Self &); //purposely not implemented
200 
203 
206 
209 };
210 } // end namespace itk
211 
212 #ifndef ITK_MANUAL_INSTANTIATION
213 #include "itkIntensityWindowingImageFilter.hxx"
214 #endif
215 
216 #endif
217