X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FAlgorithms%2FRGBToYPbPrFunction.h;h=83085fea0301c9bafdb9a956c6baf624eb9e052b;hb=aee3cafa7e93f996580777976636ed625dbc43f5;hp=5b13a075395d95e4bbd66bf47fe3d8154c410bce;hpb=2361f4f97631e09d88d8a5510a369817dcaa19db;p=cpPlugins.git diff --git a/lib/cpExtensions/Algorithms/RGBToYPbPrFunction.h b/lib/cpExtensions/Algorithms/RGBToYPbPrFunction.h index 5b13a07..83085fe 100644 --- a/lib/cpExtensions/Algorithms/RGBToYPbPrFunction.h +++ b/lib/cpExtensions/Algorithms/RGBToYPbPrFunction.h @@ -15,48 +15,55 @@ #include namespace cpExtensions +{ + namespace Algorithms { - namespace Algorithms + /** + */ + template< class P > + struct RGBToYPbPrFunction { - /** - */ - template< class O > - struct RGBToYPbPrFunction - { - typedef RGBToYPbPrFunction Self; - typedef itk::Vector< O, 3 > TOutPixel; + typedef RGBToYPbPrFunction Self; + typedef P TOutPixel; + typedef typename P::ValueType TValue; - 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 ); + template< class Tr, class Tg, class Tb > + P operator()( const Tr& r, const Tg& g, const Tb& b ) const + { + static const double M[] = + { + double( 0.2990 ), double( 0.5870 ), double( 0.1140 ), + double( -0.1687 ), double( -0.3313 ), double( 0.5000 ), + double( 0.5000 ), double( -0.4187 ), double( -0.0813 ) + }; + static const vnl_matrix< double > vM( M, 3, 3 ); + static const itk::Matrix< double, 3, 3 > iM( vM ); - TOutPixel rgb; - rgb[ 0 ] = O( r ); - rgb[ 1 ] = O( g ); - rgb[ 2 ] = O( b ); - return( iM * rgb ); - } + itk::Vector< double, 3 > rgb; + rgb[ 0 ] = double( r ); + rgb[ 1 ] = double( b ); + rgb[ 2 ] = double( g ); + rgb = iM * rgb; - template< class C > - TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const - { - return( - this->operator()( - rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( ) - ) - ); - } - }; + P out; + out[ 0 ] = TValue( rgb[ 0 ] ); + out[ 1 ] = TValue( rgb[ 1 ] ); + out[ 2 ] = TValue( rgb[ 2 ] ); + return( out ); + } - } // ecapseman + template< class C > + TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const + { + return( + this->operator()( + rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( ) + ) + ); + } + }; + + } // ecapseman } // ecapseman