// ------------------------------------------------------------------------- // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ------------------------------------------------------------------------- #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__ #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__ #include #include #include #include #include #include #include namespace cpPlugins { namespace Extensions { 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.299 ), O( 0.587 ), O( 0.114 ), O( -0.169 ), O( -0.331 ), O( 0.500 ), O( 0.500 ), O( -0.419 ), O( -0.081 ) }; 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 } // ecapseman #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__ // eof - $RCSfile$