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
00083 template <typename TInputImage, typename TOutputImage=TInputImage>
00084 class ITK_EXPORT RescaleIntensityImageFilter :
00085 public
00086 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00087 Functor::IntensityLinearTransform<
00088 typename TInputImage::PixelType,
00089 typename TOutputImage::PixelType> >
00090 {
00091 public:
00093 typedef RescaleIntensityImageFilter Self;
00094 typedef UnaryFunctorImageFilter<TInputImage,TOutputImage,
00095 Functor::IntensityLinearTransform<
00096 typename TInputImage::PixelType,
00097 typename TOutputImage::PixelType> > Superclass;
00098 typedef SmartPointer<Self> Pointer;
00099 typedef SmartPointer<const Self> ConstPointer;
00100
00101 typedef typename TOutputImage::PixelType OutputPixelType;
00102 typedef typename TInputImage::PixelType InputPixelType;
00103 typedef typename NumericTraits<InputPixelType>::RealType RealType;
00104
00106 itkNewMacro(Self);
00107
00108 itkSetMacro( OutputMinimum, OutputPixelType );
00109 itkSetMacro( OutputMaximum, OutputPixelType );
00110 itkGetConstReferenceMacro( OutputMinimum, OutputPixelType );
00111 itkGetConstReferenceMacro( OutputMaximum, OutputPixelType );
00112
00116 itkGetConstReferenceMacro( Scale, RealType );
00117 itkGetConstReferenceMacro( Shift, RealType );
00118
00121 itkGetConstReferenceMacro( InputMinimum, InputPixelType );
00122 itkGetConstReferenceMacro( InputMaximum, InputPixelType );
00123
00125 void BeforeThreadedGenerateData(void);
00126
00128 void PrintSelf(std::ostream& os, Indent indent) const;
00129
00130 protected:
00131 RescaleIntensityImageFilter();
00132 virtual ~RescaleIntensityImageFilter() {};
00133
00134 private:
00135 RescaleIntensityImageFilter(const Self&);
00136 void operator=(const Self&);
00137
00138 RealType m_Scale;
00139 RealType m_Shift;
00140
00141 InputPixelType m_InputMinimum;
00142 InputPixelType m_InputMaximum;
00143
00144 OutputPixelType m_OutputMinimum;
00145 OutputPixelType m_OutputMaximum;
00146
00147 };
00148
00149
00150
00151 }
00152
00153 #ifndef ITK_MANUAL_INSTANTIATION
00154 #include "itkRescaleIntensityImageFilter.txx"
00155 #endif
00156
00157 #endif