ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkIntensityWindowingImageFilter.h
Go to the documentation of this file.
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 
00114 template< typename  TInputImage, typename  TOutputImage = TInputImage >
00115 class ITK_EXPORT IntensityWindowingImageFilter:
00116   public
00117   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00118                            Functor::IntensityWindowingTransform<
00119                              typename TInputImage::PixelType,
00120                              typename TOutputImage::PixelType >   >
00121 {
00122 public:
00124   typedef IntensityWindowingImageFilter Self;
00125   typedef UnaryFunctorImageFilter<
00126     TInputImage, TOutputImage,
00127     Functor::IntensityWindowingTransform<
00128       typename TInputImage::PixelType,
00129       typename TOutputImage::PixelType > >  Superclass;
00130 
00131   typedef SmartPointer< Self >       Pointer;
00132   typedef SmartPointer< const Self > ConstPointer;
00133 
00134   typedef typename TOutputImage::PixelType                   OutputPixelType;
00135   typedef typename TInputImage::PixelType                    InputPixelType;
00136   typedef typename NumericTraits< InputPixelType >::RealType RealType;
00137 
00139   itkNewMacro(Self);
00140 
00142   itkTypeMacro(IntensityWindowingImageFilter,
00143                UnaryFunctorImageFilter);
00144 
00147   itkSetMacro(OutputMinimum, OutputPixelType);
00148   itkSetMacro(OutputMaximum, OutputPixelType);
00149   itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
00150   itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
00152 
00155   itkSetMacro(WindowMinimum, InputPixelType);
00156   itkSetMacro(WindowMaximum, InputPixelType);
00157   itkGetConstReferenceMacro(WindowMinimum, InputPixelType);
00158   itkGetConstReferenceMacro(WindowMaximum, InputPixelType);
00160 
00165   void SetWindowLevel(const InputPixelType & window,
00166                       const InputPixelType & level);
00167 
00168   InputPixelType GetWindow() const;
00169 
00170   InputPixelType GetLevel() const;
00171 
00175   itkGetConstReferenceMacro(Scale, RealType);
00176   itkGetConstReferenceMacro(Shift, RealType);
00178 
00180   void BeforeThreadedGenerateData(void);
00181 
00183   void PrintSelf(std::ostream & os, Indent indent) const;
00184 
00185 #ifdef ITK_USE_CONCEPT_CHECKING
00186 
00187   itkConceptMacro( InputHasNumericTraitsCheck,
00188                    ( Concept::HasNumericTraits< InputPixelType > ) );
00189 
00191 #endif
00192 protected:
00193   IntensityWindowingImageFilter();
00194   virtual ~IntensityWindowingImageFilter() {}
00195 private:
00196   IntensityWindowingImageFilter(const Self &); //purposely not implemented
00197   void operator=(const Self &);                //purposely not implemented
00199 
00200   RealType m_Scale;
00201   RealType m_Shift;
00202 
00203   InputPixelType m_WindowMinimum;
00204   InputPixelType m_WindowMaximum;
00205 
00206   OutputPixelType m_OutputMinimum;
00207   OutputPixelType m_OutputMaximum;
00208 };
00209 } // end namespace itk
00210 
00211 #ifndef ITK_MANUAL_INSTANTIATION
00212 #include "itkIntensityWindowingImageFilter.hxx"
00213 #endif
00214 
00215 #endif
00216