1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__
6 #define __CPEXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__
10 #include <vnl/vnl_math.h>
11 #include <vnl/vnl_matrix.h>
13 #include <itkRGBPixel.h>
14 #include <itkMatrix.h>
15 #include <itkVector.h>
17 namespace cpExtensions
24 struct RGBToYPbPrFunction
26 typedef RGBToYPbPrFunction Self;
28 typedef typename P::ValueType TValue;
30 template< class Tr, class Tg, class Tb >
31 P operator()( const Tr& r, const Tg& g, const Tb& b ) const
33 static const double M[] =
35 double( 0.2990 ), double( 0.5870 ), double( 0.1140 ),
36 double( -0.1687 ), double( -0.3313 ), double( 0.5000 ),
37 double( 0.5000 ), double( -0.4187 ), double( -0.0813 )
39 static const vnl_matrix< double > vM( M, 3, 3 );
40 static const itk::Matrix< double, 3, 3 > iM( vM );
42 itk::Vector< double, 3 > rgb;
43 rgb[ 0 ] = double( r );
44 rgb[ 1 ] = double( b );
45 rgb[ 2 ] = double( g );
49 out[ 0 ] = TValue( rgb[ 0 ] );
50 out[ 1 ] = TValue( rgb[ 1 ] );
51 out[ 2 ] = TValue( rgb[ 2 ] );
56 TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const
60 rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( )
70 #endif // __CPEXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__