1 #ifndef __FPA__IMAGE__FUNCTORS__IMAGEABSOLUTEDIFFERENCECOSTFUNCTION__H__
2 #define __FPA__IMAGE__FUNCTORS__IMAGEABSOLUTEDIFFERENCECOSTFUNCTION__H__
4 #include <fpa/Image/Functors/ImageCostFunction.h>
14 template< class I, class R >
15 class ImageAbsoluteDifferenceCostFunction
16 : public fpa::Image::Functors::ImageCostFunction< I, R >
19 /// Type-related and pointers
20 typedef ImageAbsoluteDifferenceCostFunction Self;
21 typedef fpa::Image::Functors::ImageCostFunction< I, R > Superclass;
22 typedef itk::SmartPointer< Self > Pointer;
23 typedef itk::SmartPointer< const Self > ConstPointer;
25 typedef typename Superclass::TInputImage TInputImage;
26 typedef typename Superclass::TResult TResult;
27 typedef typename Superclass::TIndex TIndex;
31 itkTypeMacro( ImageAbsoluteDifferenceCostFunction, itkObject );
34 virtual R Evaluate( const TIndex& v, const TIndex& p ) const
36 typedef typename I::PixelType _TPixel;
37 typedef typename itk::NumericTraits< _TPixel > _TTraits;
38 typedef typename _TTraits::MeasurementVectorType _TVector;
39 typedef typename _TTraits::ValueType _TValue;
41 if( this->m_InputImage.IsNotNull( ) )
43 _TPixel pix = this->m_InputImage->GetPixel( v );
44 pix -= this->m_InputImage->GetPixel( p );
45 if( typeid( _TPixel ) != typeid( _TValue ) )
47 _TVector* a = reinterpret_cast< _TVector* >( &pix );
49 this->m_InputImage->GetNumberOfComponentsPerPixel( );
50 double sum = double( 0 );
51 for( unsigned int i = 0; i < n; ++i )
52 sum += ( double( ( *a )[ i ] ) * double( ( *a )[ i ] ) );
53 return( R( std::sqrt( sum ) ) );
58 double( *( reinterpret_cast< _TValue* >( &pix ) ) );
59 return( R( std::fabs( pix_val ) ) );
63 return( std::numeric_limits< R >::max( ) );
67 ImageAbsoluteDifferenceCostFunction( )
70 virtual ~ImageAbsoluteDifferenceCostFunction( )
74 // Purposely not implemented
75 ImageAbsoluteDifferenceCostFunction( const Self& );
76 void operator=( const Self& );
85 #endif // __FPA__IMAGE__FUNCTORS__IMAGEABSOLUTEDIFFERENCECOSTFUNCTION__H__