// ------------------------------------------------------------------------- // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ------------------------------------------------------------------------- #ifndef __CPEXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__ #define __CPEXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__ #include #include #include #include #include #include #include namespace cpExtensions { namespace Algorithms { /** */ template< class O > struct RGBToYPbPrFunction { typedef RGBToYPbPrFunction Self; typedef itk::Vector< O, 3 > TOutPixel; template< class Tr, class Tg, class Tb > TOutPixel operator()( const Tr& r, const Tg& g, const Tb& b ) const { static const O M[] = { O( 0.2990 ), O( 0.5870 ), O( 0.1140 ), O( -0.1687 ), O( -0.3313 ), O( 0.5000 ), O( 0.5000 ), O( -0.4187 ), O( -0.0813 ) }; static const vnl_matrix< O > vM( M, 3, 3 ); static const itk::Matrix< O, 3, 3 > iM( vM ); TOutPixel rgb; rgb[ 0 ] = O( r ); rgb[ 1 ] = O( g ); rgb[ 2 ] = O( b ); return( iM * rgb ); } template< class C > TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const { return( this->operator()( rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( ) ) ); } }; } // ecapseman } // ecapseman #endif // __CPEXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__ // eof - $RCSfile$