00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkRescaleIntensityImageFilter_h
00018 #define __itkRescaleIntensityImageFilter_h
00019
00020 #include "itkUnaryFunctorImageFilter.h"
00021
00022 namespace itk
00023 {
00024
00025
00026
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 ~IntensityLinearTransform() {}
00036 void SetFactor( RealType a ) { m_Factor = a; }
00037 void SetOffset( RealType b ) { m_Offset = b; }
00038 void SetMinimum( TOutput min ) { m_Minimum = min; }
00039 void SetMaximum( TOutput max ) { m_Maximum = max; }
00040 inline TOutput operator()( const TInput & x )
00041 {
00042 RealType value = static_cast<RealType>(x) * m_Factor + m_Offset;
00043 TOutput result = static_cast<TOutput>( value );
00044 result = ( result > m_Maximum ) ? m_Maximum : result;
00045 result = ( result < m_Minimum ) ? m_Minimum : result;
00046 return result;
00047 }
00048 private:
00049 RealType m_Factor;
00050 RealType m_Offset;
00051 TOutput m_Maximum;
00052 TOutput m_Minimum;
00053 };
00054
00055 }
00056
00057
00073 template <typename TInputImage, typename TOutputImage=TInputImage>
00074 class ITK_EXPORT RescaleIntensityImageFilter :
00075 public
00076 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00077 Functor::IntensityLinearTransform<
00078 typename TInputImage::PixelType,
00079 typename TOutputImage::PixelType> >
00080 {
00081 public:
00083 typedef RescaleIntensityImageFilter Self;
00084 typedef UnaryFunctorImageFilter<TInputImage,TOutputImage,
00085 Functor::IntensityLinearTransform<
00086 typename TInputImage::PixelType,
00087 typename TOutputImage::PixelType> > Superclass;
00088 typedef SmartPointer<Self> Pointer;
00089 typedef SmartPointer<const Self> ConstPointer;
00090
00091 typedef typename TOutputImage::PixelType OutputPixelType;
00092 typedef typename TInputImage::PixelType InputPixelType;
00093 typedef typename NumericTraits<InputPixelType>::RealType RealType;
00094
00096 itkNewMacro(Self);
00097
00098 itkSetMacro( OutputMinimum, OutputPixelType );
00099 itkSetMacro( OutputMaximum, OutputPixelType );
00100 itkGetConstMacro( OutputMinimum, OutputPixelType );
00101 itkGetConstMacro( OutputMaximum, OutputPixelType );
00102
00106 itkGetConstMacro( Scale, RealType );
00107 itkGetConstMacro( Shift, RealType );
00108
00111 itkGetConstMacro( InputMinimum, InputPixelType );
00112 itkGetConstMacro( InputMaximum, InputPixelType );
00113
00114
00116 void BeforeThreadedGenerateData(void);
00117
00119 void PrintSelf(std::ostream& os, Indent indent) const;
00120
00121 protected:
00122 RescaleIntensityImageFilter();
00123 virtual ~RescaleIntensityImageFilter() {};
00124
00125 private:
00126 RescaleIntensityImageFilter(const Self&);
00127 void operator=(const Self&);
00128
00129 RealType m_Scale;
00130 RealType m_Shift;
00131
00132 InputPixelType m_InputMinimum;
00133 InputPixelType m_InputMaximum;
00134
00135 OutputPixelType m_OutputMinimum;
00136 OutputPixelType m_OutputMaximum;
00137
00138 };
00139
00140
00141
00142 }
00143
00144 #ifndef ITK_MANUAL_INSTANTIATION
00145 #include "itkRescaleIntensityImageFilter.txx"
00146 #endif
00147
00148 #endif