X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FAlgorithms%2FRGBToHSVFunction.h;h=b10f2954976a85e6727fa862ef8edd425d000257;hb=f1747c7248d5eead5ea9d7e57bda0b081bcef065;hp=326ec5d058f12d490e25cc626df8fff994d7bbeb;hpb=506b27e2ea07cb34ba230b02eb6857b20cbf78b1;p=cpPlugins.git diff --git a/lib/cpExtensions/Algorithms/RGBToHSVFunction.h b/lib/cpExtensions/Algorithms/RGBToHSVFunction.h index 326ec5d..b10f295 100644 --- a/lib/cpExtensions/Algorithms/RGBToHSVFunction.h +++ b/lib/cpExtensions/Algorithms/RGBToHSVFunction.h @@ -10,7 +10,6 @@ #include #include -#include namespace cpExtensions { @@ -18,24 +17,25 @@ namespace cpExtensions { /** */ - template< class O > + template< class P > struct RGBToHSVFunction { - typedef RGBToHSVFunction Self; - typedef itk::Vector< O, 3 > TOutPixel; + typedef RGBToHSVFunction 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 + P operator()( const Tr& r, const Tg& g, const Tb& b ) const { static const double mVal = - double( std::numeric_limits< O >::max( ) ); + double( std::numeric_limits< TValue >::max( ) ); static const double _0 = double( 0 ); static const double _1 = double( 1 ); static const double _2 = double( 2 ); static const double _3 = double( 3 ); static const double _2pi = _2 * double( vnl_math::pi ); - TOutPixel hsv; + P hsv; double R = double( r ); double G = double( g ); @@ -50,20 +50,20 @@ namespace cpExtensions if( A != _0 ) A = std::acos( ( RG + RB ) / ( _2 * A ) ); A /= _2pi; - hsv[ 0 ] = O( mVal * ( ( G >= B )? A: _1 - A ) ); + hsv[ 0 ] = TValue( mVal * ( ( G >= B )? A: _1 - A ) ); // Saturation if( sRGB != _0 ) { double C = ( G < R )? G: R; C = ( B < C )? B: C; - hsv[ 1 ] = O( mVal * ( _1 - ( ( _3 * C ) / sRGB ) ) ); + hsv[ 1 ] = TValue( mVal * ( _1 - ( ( _3 * C ) / sRGB ) ) ); } else - hsv[ 1 ] = O( 0 ); + hsv[ 1 ] = TValue( 0 ); // Value - hsv[ 2 ] = O( sRGB / _3 ); + hsv[ 2 ] = TValue( sRGB / _3 ); return( hsv ); }