ITK
4.0.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkIntensityWindowingImageFilter_h 00019 #define __itkIntensityWindowingImageFilter_h 00020 00021 #include "itkUnaryFunctorImageFilter.h" 00022 00023 namespace itk 00024 { 00025 // This functor class applies a linear transformation A.x + B inside a specified 00026 // range. Values below the range are mapped to a constant. Values over the range 00027 // are mapped to another constant. 00028 namespace Functor 00029 { 00030 template< typename TInput, typename TOutput > 00031 class IntensityWindowingTransform 00032 { 00033 public: 00034 typedef typename NumericTraits< TInput >::RealType RealType; 00035 IntensityWindowingTransform() {} 00036 ~IntensityWindowingTransform() {} 00037 bool operator!=(const IntensityWindowingTransform & other) const 00038 { 00039 if ( m_Factor != other.m_Factor 00040 || m_Offset != other.m_Offset 00041 || m_OutputMaximum != other.m_OutputMaximum 00042 || m_OutputMinimum != other.m_OutputMinimum 00043 || m_WindowMaximum != other.m_WindowMaximum 00044 || m_WindowMinimum != other.m_WindowMinimum ) 00045 { 00046 return true; 00047 } 00048 return false; 00049 } 00050 00051 bool operator==(const IntensityWindowingTransform & other) const 00052 { 00053 return !( *this != other ); 00054 } 00055 00056 void SetFactor(RealType a) { m_Factor = a; } 00057 void SetOffset(RealType b) { m_Offset = b; } 00058 void SetOutputMinimum(TOutput min) { m_OutputMinimum = min; } 00059 void SetOutputMaximum(TOutput max) { m_OutputMaximum = max; } 00060 void SetWindowMinimum(TInput min) { m_WindowMinimum = min; } 00061 void SetWindowMaximum(TInput max) { m_WindowMaximum = max; } 00062 inline TOutput operator()(const TInput & x) const 00063 { 00064 if ( x < m_WindowMinimum ) 00065 { 00066 return m_OutputMinimum; 00067 } 00068 if ( x > m_WindowMaximum ) 00069 { 00070 return m_OutputMaximum; 00071 } 00072 const RealType value = static_cast< RealType >( x ) * m_Factor + m_Offset; 00073 const TOutput result = static_cast< TOutput >( value ); 00074 return result; 00075 } 00076 00077 private: 00078 RealType m_Factor; 00079 RealType m_Offset; 00080 TOutput m_OutputMaximum; 00081 TOutput m_OutputMinimum; 00082 TInput m_WindowMaximum; 00083 TInput m_WindowMinimum; 00084 }; 00085 } // end namespace functor 00086 00112 template< typename TInputImage, typename TOutputImage = TInputImage > 00113 class ITK_EXPORT IntensityWindowingImageFilter: 00114 public 00115 UnaryFunctorImageFilter< TInputImage, TOutputImage, 00116 Functor::IntensityWindowingTransform< 00117 typename TInputImage::PixelType, 00118 typename TOutputImage::PixelType > > 00119 { 00120 public: 00122 typedef IntensityWindowingImageFilter Self; 00123 typedef UnaryFunctorImageFilter< 00124 TInputImage, TOutputImage, 00125 Functor::IntensityWindowingTransform< 00126 typename TInputImage::PixelType, 00127 typename TOutputImage::PixelType > > Superclass; 00128 00129 typedef SmartPointer< Self > Pointer; 00130 typedef SmartPointer< const Self > ConstPointer; 00131 00132 typedef typename TOutputImage::PixelType OutputPixelType; 00133 typedef typename TInputImage::PixelType InputPixelType; 00134 typedef typename NumericTraits< InputPixelType >::RealType RealType; 00135 00137 itkNewMacro(Self); 00138 00140 itkTypeMacro(IntensityWindowingImageFilter, 00141 UnaryFunctorImageFilter); 00142 00145 itkSetMacro(OutputMinimum, OutputPixelType); 00146 itkSetMacro(OutputMaximum, OutputPixelType); 00147 itkGetConstReferenceMacro(OutputMinimum, OutputPixelType); 00148 itkGetConstReferenceMacro(OutputMaximum, OutputPixelType); 00150 00153 itkSetMacro(WindowMinimum, InputPixelType); 00154 itkSetMacro(WindowMaximum, InputPixelType); 00155 itkGetConstReferenceMacro(WindowMinimum, InputPixelType); 00156 itkGetConstReferenceMacro(WindowMaximum, InputPixelType); 00158 00163 void SetWindowLevel(const InputPixelType & window, 00164 const InputPixelType & level); 00165 00166 InputPixelType GetWindow() const; 00167 00168 InputPixelType GetLevel() const; 00169 00173 itkGetConstReferenceMacro(Scale, RealType); 00174 itkGetConstReferenceMacro(Shift, RealType); 00176 00178 void BeforeThreadedGenerateData(void); 00179 00181 void PrintSelf(std::ostream & os, Indent indent) const; 00182 00183 #ifdef ITK_USE_CONCEPT_CHECKING 00184 00185 itkConceptMacro( InputHasNumericTraitsCheck, 00186 ( Concept::HasNumericTraits< InputPixelType > ) ); 00187 00189 #endif 00190 protected: 00191 IntensityWindowingImageFilter(); 00192 virtual ~IntensityWindowingImageFilter() {} 00193 private: 00194 IntensityWindowingImageFilter(const Self &); //purposely not implemented 00195 void operator=(const Self &); //purposely not implemented 00197 00198 RealType m_Scale; 00199 RealType m_Shift; 00200 00201 InputPixelType m_WindowMinimum; 00202 InputPixelType m_WindowMaximum; 00203 00204 OutputPixelType m_OutputMinimum; 00205 OutputPixelType m_OutputMaximum; 00206 }; 00207 } // end namespace itk 00208 00209 #ifndef ITK_MANUAL_INSTANTIATION 00210 #include "itkIntensityWindowingImageFilter.hxx" 00211 #endif 00212 00213 #endif 00214