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 bool operator!=( const IntensityLinearTransform & other ) const
00041 {
00042 if( m_Factor != other.m_Factor ||
00043 m_Offset != other.m_Offset ||
00044 m_Maximum != other.m_Maximum ||
00045 m_Minimum != other.m_Minimum )
00046 {
00047 return true;
00048 }
00049 return false;
00050 }
00051 bool operator==( const IntensityLinearTransform & other ) const
00052 {
00053 return !(*this != other);
00054 }
00055 inline TOutput operator()( const TInput & x )
00056 {
00057 RealType value = static_cast<RealType>(x) * m_Factor + m_Offset;
00058 TOutput result = static_cast<TOutput>( value );
00059 result = ( result > m_Maximum ) ? m_Maximum : result;
00060 result = ( result < m_Minimum ) ? m_Minimum : result;
00061 return result;
00062 }
00063 private:
00064 RealType m_Factor;
00065 RealType m_Offset;
00066 TOutput m_Maximum;
00067 TOutput m_Minimum;
00068 };
00069
00070 }
00071
00072
00098 template <typename TInputImage, typename TOutputImage=TInputImage>
00099 class ITK_EXPORT RescaleIntensityImageFilter :
00100 public
00101 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00102 Functor::IntensityLinearTransform<
00103 typename TInputImage::PixelType,
00104 typename TOutputImage::PixelType> >
00105 {
00106 public:
00108 typedef RescaleIntensityImageFilter Self;
00109 typedef UnaryFunctorImageFilter<TInputImage,TOutputImage,
00110 Functor::IntensityLinearTransform<
00111 typename TInputImage::PixelType,
00112 typename TOutputImage::PixelType> > Superclass;
00113 typedef SmartPointer<Self> Pointer;
00114 typedef SmartPointer<const Self> ConstPointer;
00115
00116 typedef typename TOutputImage::PixelType OutputPixelType;
00117 typedef typename TInputImage::PixelType InputPixelType;
00118 typedef typename NumericTraits<InputPixelType>::RealType RealType;
00119
00121 itkNewMacro(Self);
00122
00123 itkSetMacro( OutputMinimum, OutputPixelType );
00124 itkSetMacro( OutputMaximum, OutputPixelType );
00125 itkGetConstReferenceMacro( OutputMinimum, OutputPixelType );
00126 itkGetConstReferenceMacro( OutputMaximum, OutputPixelType );
00127
00131 itkGetConstReferenceMacro( Scale, RealType );
00132 itkGetConstReferenceMacro( Shift, RealType );
00134
00137 itkGetConstReferenceMacro( InputMinimum, InputPixelType );
00138 itkGetConstReferenceMacro( InputMaximum, InputPixelType );
00140
00142 void BeforeThreadedGenerateData(void);
00143
00145 void PrintSelf(std::ostream& os, Indent indent) const;
00146
00147 #ifdef ITK_USE_CONCEPT_CHECKING
00148
00149 itkConceptMacro(InputHasNumericTraitsCheck,
00150 (Concept::HasNumericTraits<InputPixelType>));
00151 itkConceptMacro(OutputHasNumericTraitsCheck,
00152 (Concept::HasNumericTraits<OutputPixelType>));
00153 itkConceptMacro(RealTypeMultiplyOperatorCheck,
00154 (Concept::MultiplyOperator<RealType>));
00155 itkConceptMacro(RealTypeAdditiveOperatorsCheck,
00156 (Concept::AdditiveOperators<RealType>));
00157
00159 #endif
00160
00161 protected:
00162 RescaleIntensityImageFilter();
00163 virtual ~RescaleIntensityImageFilter() {};
00164
00165 private:
00166 RescaleIntensityImageFilter(const Self&);
00167 void operator=(const Self&);
00168
00169 RealType m_Scale;
00170 RealType m_Shift;
00171
00172 InputPixelType m_InputMinimum;
00173 InputPixelType m_InputMaximum;
00174
00175 OutputPixelType m_OutputMinimum;
00176 OutputPixelType m_OutputMaximum;
00177
00178 };
00179
00180
00181
00182 }
00183
00184 #ifndef ITK_MANUAL_INSTANTIATION
00185 #include "itkRescaleIntensityImageFilter.txx"
00186 #endif
00187
00188 #endif
00189