]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Algorithms/RGBToYPbPrFunction.h
56ffd5c6a72eaa2c7b4144d9888b6f8b04a6c414
[cpPlugins.git] / lib / cpPlugins / Extensions / Algorithms / RGBToYPbPrFunction.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__
7
8 #include <cmath>
9 #include <limits>
10 #include <vnl/vnl_math.h>
11 #include <vnl/vnl_matrix.h>
12
13 #include <itkRGBPixel.h>
14 #include <itkMatrix.h>
15 #include <itkVector.h>
16
17 namespace cpPlugins
18 {
19   namespace Extensions
20   {
21     namespace Algorithms
22     {
23       /**
24        */
25       template< class O >
26       struct RGBToYPbPrFunction
27       {
28         typedef RGBToYPbPrFunction  Self;
29         typedef itk::Vector< O, 3 > TOutPixel;
30
31         template< class Tr, class Tg, class Tb >
32         TOutPixel operator()( const Tr& r, const Tg& g, const Tb& b ) const
33           {
34             static const O M[] =
35               {
36                 O(  0.2990 ), O(  0.5870 ), O(  0.1140 ),
37                 O( -0.1687 ), O( -0.3313 ), O(  0.5000 ),
38                 O(  0.5000 ), O( -0.4187 ), O( -0.0813 )
39               };
40             static const vnl_matrix< O > vM( M, 3, 3 );
41             static const itk::Matrix< O, 3, 3 > iM( vM );
42
43             TOutPixel rgb;
44             rgb[ 0 ] = O( r );
45             rgb[ 1 ] = O( g );
46             rgb[ 2 ] = O( b );
47             return( iM * rgb );
48           }
49
50         template< class C >
51         TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const
52           {
53             return(
54               this->operator()(
55                 rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( )
56                 )
57               );
58           }
59       };
60
61     } // ecapseman
62
63   } // ecapseman
64
65 } // ecapseman
66
67 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBTOYPBPRFUNCTION__H__
68
69 // eof - $RCSfile$