itkRescaleIntensityImageFilter.h
Go to the documentation of this file.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 {
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 ) const
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 }
00077
00078
00112 template <typename TInputImage, typename TOutputImage=TInputImage>
00113 class ITK_EXPORT RescaleIntensityImageFilter :
00114 public
00115 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00116 Functor::IntensityLinearTransform<
00117 typename TInputImage::PixelType,
00118 typename TOutputImage::PixelType> >
00119 {
00120 public:
00122 typedef RescaleIntensityImageFilter Self;
00123 typedef UnaryFunctorImageFilter<
00124 TInputImage,TOutputImage,
00125 Functor::IntensityLinearTransform<
00126 typename TInputImage::PixelType,
00127 typename TOutputImage::PixelType> > Superclass;
00128 typedef SmartPointer<Self> Pointer;
00129 typedef SmartPointer<const Self> ConstPointer;
00130
00131 typedef typename TOutputImage::PixelType OutputPixelType;
00132 typedef typename TInputImage::PixelType InputPixelType;
00133 typedef typename NumericTraits<InputPixelType>::RealType RealType;
00134
00136 itkNewMacro(Self);
00137
00139 itkTypeMacro(RescaleIntensityImageFilter,
00140 UnaryFunctorImageFilter);
00141
00142 itkSetMacro( OutputMinimum, OutputPixelType );
00143 itkSetMacro( OutputMaximum, OutputPixelType );
00144 itkGetConstReferenceMacro( OutputMinimum, OutputPixelType );
00145 itkGetConstReferenceMacro( OutputMaximum, OutputPixelType );
00146
00150 itkGetConstReferenceMacro( Scale, RealType );
00151 itkGetConstReferenceMacro( Shift, RealType );
00153
00156 itkGetConstReferenceMacro( InputMinimum, InputPixelType );
00157 itkGetConstReferenceMacro( InputMaximum, InputPixelType );
00159
00161 void BeforeThreadedGenerateData(void);
00162
00164 void PrintSelf(std::ostream& os, Indent indent) const;
00165
00166 #ifdef ITK_USE_CONCEPT_CHECKING
00167
00168 itkConceptMacro(InputHasNumericTraitsCheck,
00169 (Concept::HasNumericTraits<InputPixelType>));
00170 itkConceptMacro(OutputHasNumericTraitsCheck,
00171 (Concept::HasNumericTraits<OutputPixelType>));
00172 itkConceptMacro(RealTypeMultiplyOperatorCheck,
00173 (Concept::MultiplyOperator<RealType>));
00174 itkConceptMacro(RealTypeAdditiveOperatorsCheck,
00175 (Concept::AdditiveOperators<RealType>));
00176
00178 #endif
00179
00180 protected:
00181 RescaleIntensityImageFilter();
00182 virtual ~RescaleIntensityImageFilter() {};
00183
00184 private:
00185 RescaleIntensityImageFilter(const Self&);
00186 void operator=(const Self&);
00187
00188 RealType m_Scale;
00189 RealType m_Shift;
00190
00191 InputPixelType m_InputMinimum;
00192 InputPixelType m_InputMaximum;
00193
00194 OutputPixelType m_OutputMinimum;
00195 OutputPixelType m_OutputMaximum;
00196
00197 };
00198
00199
00200
00201 }
00202
00203 #ifndef ITK_MANUAL_INSTANTIATION
00204 #include "itkRescaleIntensityImageFilter.txx"
00205 #endif
00206
00207 #endif
00208