Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkRescaleIntensityImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkRescaleIntensityImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-10-17 16:30:52 $
00007   Version:   $Revision: 1.16 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkRescaleIntensityImageFilter_h
00018 #define __itkRescaleIntensityImageFilter_h
00019 
00020 #include "itkUnaryFunctorImageFilter.h"
00021 
00022 namespace itk
00023 {
00024 
00025 // This functor class applies a linear transformation A.x + B 
00026 // to input values.
00027 namespace Functor {  
00028  
00029 template< typename TInput, typename  TOutput>
00030 class IntensityLinearTransform
00031 {
00032 public:
00033   typedef typename NumericTraits< TInput >::RealType RealType;
00034   IntensityLinearTransform()
00035     {
00036     m_Factor = 1.0;
00037     m_Offset = 0.0;
00038     m_Minimum = NumericTraits<TOutput>::NonpositiveMin();
00039     m_Maximum = NumericTraits<TOutput>::max();
00040     }
00041   ~IntensityLinearTransform() {}
00042   void SetFactor( RealType a ) { m_Factor = a; }
00043   void SetOffset( RealType b ) { m_Offset = b; }
00044   void SetMinimum( TOutput min ) { m_Minimum = min; }
00045   void SetMaximum( TOutput max ) { m_Maximum = max; }
00046   bool operator!=( const IntensityLinearTransform & other ) const
00047     {
00048     if( m_Factor != other.m_Factor ||
00049         m_Offset != other.m_Offset ||
00050         m_Maximum != other.m_Maximum    ||
00051         m_Minimum != other.m_Minimum )
00052       {
00053       return true;
00054       }
00055     return false;
00056     }
00057   bool operator==( const IntensityLinearTransform & other ) const
00058     {
00059     return !(*this != other);
00060     }
00061   inline TOutput operator()( const TInput & x )
00062     {
00063     RealType value  = static_cast<RealType>(x) * m_Factor + m_Offset;
00064     TOutput  result = static_cast<TOutput>( value );
00065     result = ( result > m_Maximum ) ? m_Maximum : result;
00066     result = ( result < m_Minimum ) ? m_Minimum : result;
00067     return result;
00068     }
00069 private:
00070   RealType m_Factor;
00071   RealType m_Offset;
00072   TOutput  m_Maximum;
00073   TOutput  m_Minimum;
00074 }; 
00075 
00076 }  // end namespace functor
00077 
00078 
00104 template <typename  TInputImage, typename  TOutputImage=TInputImage>
00105 class ITK_EXPORT RescaleIntensityImageFilter :
00106     public
00107 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00108                         Functor::IntensityLinearTransform< 
00109   typename TInputImage::PixelType, 
00110   typename TOutputImage::PixelType>   >
00111 {
00112 public:
00114   typedef RescaleIntensityImageFilter      Self;
00115   typedef UnaryFunctorImageFilter<
00116     TInputImage,TOutputImage, 
00117     Functor::IntensityLinearTransform< 
00118       typename TInputImage::PixelType, 
00119       typename TOutputImage::PixelType> >  Superclass;
00120   typedef SmartPointer<Self>               Pointer;
00121   typedef SmartPointer<const Self>         ConstPointer;
00122 
00123   typedef typename TOutputImage::PixelType                 OutputPixelType;
00124   typedef typename TInputImage::PixelType                  InputPixelType;
00125   typedef typename NumericTraits<InputPixelType>::RealType RealType;
00126 
00128   itkNewMacro(Self);
00129 
00131   itkTypeMacro(RescaleIntensityImageFilter, 
00132                UnaryFunctorImageFilter);
00133 
00134   itkSetMacro( OutputMinimum, OutputPixelType );
00135   itkSetMacro( OutputMaximum, OutputPixelType );
00136   itkGetConstReferenceMacro( OutputMinimum, OutputPixelType );
00137   itkGetConstReferenceMacro( OutputMaximum, OutputPixelType );
00138 
00142   itkGetConstReferenceMacro( Scale, RealType );
00143   itkGetConstReferenceMacro( Shift, RealType );
00145 
00148   itkGetConstReferenceMacro( InputMinimum, InputPixelType );
00149   itkGetConstReferenceMacro( InputMaximum, InputPixelType );
00151 
00153   void BeforeThreadedGenerateData(void);
00154 
00156   void PrintSelf(std::ostream& os, Indent indent) const;
00157 
00158 #ifdef ITK_USE_CONCEPT_CHECKING
00159 
00160   itkConceptMacro(InputHasNumericTraitsCheck,
00161                   (Concept::HasNumericTraits<InputPixelType>));
00162   itkConceptMacro(OutputHasNumericTraitsCheck,
00163                   (Concept::HasNumericTraits<OutputPixelType>));
00164   itkConceptMacro(RealTypeMultiplyOperatorCheck,
00165                   (Concept::MultiplyOperator<RealType>));
00166   itkConceptMacro(RealTypeAdditiveOperatorsCheck,
00167                   (Concept::AdditiveOperators<RealType>));
00168 
00170 #endif
00171 
00172 protected:
00173   RescaleIntensityImageFilter();
00174   virtual ~RescaleIntensityImageFilter() {};
00175 
00176 private:
00177   RescaleIntensityImageFilter(const Self&); //purposely not implemented
00178   void operator=(const Self&); //purposely not implemented
00179 
00180   RealType m_Scale;
00181   RealType m_Shift;
00182 
00183   InputPixelType        m_InputMinimum;
00184   InputPixelType        m_InputMaximum;
00185 
00186   OutputPixelType       m_OutputMinimum;
00187   OutputPixelType       m_OutputMaximum;
00188 
00189 };
00190 
00191 
00192   
00193 } // end namespace itk
00194   
00195 #ifndef ITK_MANUAL_INSTANTIATION
00196 #include "itkRescaleIntensityImageFilter.txx"
00197 #endif
00198   
00199 #endif
00200 

Generated at Wed Nov 5 23:58:45 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000