Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpHSV< T, useFullScale > Class Template Reference

#include <vpHSV.h>

Public Member Functions

 vpHSV (const double &H_=0., const double &S_=0., const double &V_=0.)
 vpHSV (const vpColVector &v)
 vpHSV (const vpHSV< T, useFullScale > &)=default
template<typename U = T, typename V, typename std::enable_if< std::is_same< T, unsigned char >::value &&std::is_floating_point< V >::value &&useFullScale, U >::type = 0>
 vpHSV (const vpHSV< V > &other)
template<typename U = T, typename V, typename std::enable_if< std::is_same< T, unsigned char >::value &&std::is_floating_point< V >::value &&!useFullScale, U >::type = 0>
 vpHSV (const vpHSV< V > &other)
template<typename U = T, bool otherUseFullScale, typename std::enable_if< std::is_floating_point< U >::value >::type...>
 vpHSV (const vpHSV< unsigned char, otherUseFullScale > &other)
 vpHSV (const vpRGBa &rgba)
virtual ~vpHSV ()=default
vpHSV< T, useFullScale > & buildFrom (const vpRGBa &rgba)
template<typename V, bool otherUseFullScale>
std::enable_if< std::is_same< T, unsignedchar >::value &&std::is_floating_point< V >::value &&useFullScale, vpHSV< T, useFullScale > & >::type buildFrom (const vpHSV< V, otherUseFullScale > &other)
template<typename U = T, typename V, bool otherUseFullScale>
std::enable_if< std::is_same< U, unsignedchar >::value &&std::is_floating_point< V >::value &&!useFullScale, vpHSV< T, useFullScale > & >::type buildFrom (const vpHSV< V, otherUseFullScale > &other)
template<typename U = T, bool otherUseFullScale>
std::enable_if< std::is_floating_point< U >::value, vpHSV< T, useFullScale > & >::type buildFrom (const vpHSV< unsigned char, otherUseFullScale > &other)
template<typename U = T, typename V, bool otherUseFullScale>
std::enable_if< std::is_floating_point< U >::value &&std::is_floating_point< V >::value &&!std::is_same< T, V >::value, vpHSV< T, useFullScale > & >::type buildFrom (const vpHSV< V, otherUseFullScale > &other)
vpHSV< T, useFullScale > & operator= (vpHSV< T, useFullScale > &&)=default
vpHSV< T, useFullScale > & operator= (const vpHSV< T, useFullScale > &)=default
vpHSV< T, useFullScale > & operator= (const vpColVector &v)
bool operator== (const vpHSV< T, useFullScale > &v) const
bool operator!= (const vpHSV< T, useFullScale > &v) const
vpColVector operator- (const vpHSV< T, useFullScale > &v) const
vpHSV< T, useFullScale > operator+ (const vpHSV< T, useFullScale > &v) const
vpColVector operator- (const vpColVector &v) const
vpColVector operator+ (const vpColVector &v) const
vpColVector toColVector () const
virtual std::string toString () const
VISP_EXPORT vpHSV< unsigned char, false > & buildFrom (const vpRGBa &rgba)
VISP_EXPORT vpHSV< unsigned char, true > & buildFrom (const vpRGBa &rgba)
VISP_EXPORT vpHSV< double > & buildFrom (const vpRGBa &rgba)
BEGIN_VISP_NAMESPACE vpHSV< double > & buildFrom (const vpRGBa &rgba)
vpHSV< unsigned char, true > & buildFrom (const vpRGBa &rgba)
vpHSV< unsigned char, false > & buildFrom (const vpRGBa &rgba)

Static Public Member Functions

static vpColVector computeNormalizedHSV (const vpRGBa &rgba)
template<typename ArithmeticType>
static ArithmeticType squaredMahalanobisDistance (const vpHSV< T, useFullScale > &a, const vpHSV< T, useFullScale > &b, vpColVector &diff)
template<typename ArithmeticType>
static ArithmeticType squaredMahalanobisDistance (const vpHSV< T, useFullScale > &a, const vpHSV< T, useFullScale > &b)
template<typename ArithmeticType>
static ArithmeticType mahalanobisDistance (const vpHSV< T, useFullScale > &a, const vpHSV< T, useFullScale > &b)
template<typename ArithmeticType>
static ArithmeticType mahalanobisDistance (const vpHSV< T, useFullScale > &a, const vpHSV< T, useFullScale > &b, vpColVector &diff)

Public Attributes

H
S
V

Static Public Attributes

static constexpr unsigned char nbChannels = 3
static constexpr unsigned char maxHueUsingLimitedRange = 179

Friends

std::ostream & operator<< (std::ostream &os, const vpHSV< T, useFullScale > &hsv)

Detailed Description

template<typename T, bool useFullScale>
class vpHSV< T, useFullScale >

Class implementing the HSV pixel format.

Template Parameters
TThe type of the channels. Either a floating point type (float, double) or unsigned char.
useFullScaleTrue if vpHSV uses unsigned char and the full range [0; 255], false if vpHSV uses unsigned char and the limited range [0; maxHueUsingLimitedRange].

Tutorials & Examples

Tutorials
If you are interested in how you can convert vpHSV to and from other type of data, or how to use it for color segmentation, you may have a look at:

Examples
testHSVGradient.cpp, testHSVtoHSV.cpp, testHSVtoRGBa.cpp, testImageFilterHSVOldVSNew.cpp, and testRGBaToHSV.cpp.

Definition at line 134 of file vpHSV.h.

Constructor & Destructor Documentation

◆ vpHSV() [1/7]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale >::vpHSV ( const double & H_ = 0.,
const double & S_ = 0.,
const double & V_ = 0. )
inlineexplicit

Construct a new vpHSV object using floating point channels.

Template Parameters
UThe type of the channels of the vpHSV pixels.
Parameters
[in]H_The value of the Hue channel.
[in]S_The value of the Saturation channel.
[in]V_The value of the Value channel.

Definition at line 145 of file vpHSV.h.

References H, S, and V.

Referenced by buildFrom(), buildFrom(), buildFrom(), mahalanobisDistance(), mahalanobisDistance(), operator!=(), operator+(), operator-(), operator<<, operator=(), operator=(), operator=(), operator==(), squaredMahalanobisDistance(), squaredMahalanobisDistance(), vpHSV(), vpHSV(), and vpHSV().

◆ vpHSV() [2/7]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale >::vpHSV ( const vpColVector & v)
inline

Construct a new vpHSV object from a vpColVector.

Parameters
[in]vThe values must be in the range that corresponds to the type used to encode the channels.

Definition at line 157 of file vpHSV.h.

◆ vpHSV() [3/7]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale >::vpHSV ( const vpHSV< T, useFullScale > & )
default

Default copy constructor.

References vpHSV().

◆ vpHSV() [4/7]

template<typename T, bool useFullScale>
template<typename U = T, typename V, typename std::enable_if< std::is_same< T, unsigned char >::value &&std::is_floating_point< V >::value &&useFullScale, U >::type = 0>
vpHSV< T, useFullScale >::vpHSV ( const vpHSV< V > & other)
inline

Construct a new vpHSV object using unsigned char channels and the full range [0; 255] from a vpHSV object whose channels are in floating point format.

Template Parameters
UThe format of the constructed object.
VThe format of the base object.
typeEnable the method only if the constructed object uses unsigned char format and uses the full range [0; 255] and the object that is used as reference uses floating point format.
Parameters
[in]otherA floating point format vpHSV.

Definition at line 179 of file vpHSV.h.

References buildFrom(), and vpHSV().

◆ vpHSV() [5/7]

template<typename T, bool useFullScale>
template<typename U = T, typename V, typename std::enable_if< std::is_same< T, unsigned char >::value &&std::is_floating_point< V >::value &&!useFullScale, U >::type = 0>
vpHSV< T, useFullScale >::vpHSV ( const vpHSV< V > & other)
inline

Construct a new vpHSV object using unsigned char channels and the limited range [0; maxHueUsingLimitedRange] from a vpHSV object whose channels are in floating point format.

Template Parameters
UThe format of the constructed object.
VThe format of the base object.
typeEnable the method only if the constructed object uses unsigned char format and uses the limited range [0; maxHueUsingLimitedRange] and the object that is used as reference uses floating point format.
Parameters
[in]otherA floating point format vpHSV.

Definition at line 195 of file vpHSV.h.

References buildFrom(), and vpHSV().

◆ vpHSV() [6/7]

template<typename T, bool useFullScale>
template<typename U = T, bool otherUseFullScale, typename std::enable_if< std::is_floating_point< U >::value >::type...>
vpHSV< T, useFullScale >::vpHSV ( const vpHSV< unsigned char, otherUseFullScale > & other)
inline

Construct a new floating point vpHSV object from an unsigned char vpHSV object.

Template Parameters
UThe type of the channels of the constructed vpHSV pixels.
otherUseFullScaleTrue if the reference object uses unsigned char and the full range [0; 255], false if it uses unsigned char and the limited range [0; maxHueUsingLimitedRange].
typeEnable the method only if the constructed object uses the floating point format for its channels.
Parameters
[in]otherThe reference object.

Definition at line 210 of file vpHSV.h.

References buildFrom(), and vpHSV().

◆ vpHSV() [7/7]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale >::vpHSV ( const vpRGBa & rgba)
inline

Construct a new vpHSV object from a vpRGBa object.

Parameters
[in]rgbaThe reference vpRGBa object.

Definition at line 221 of file vpHSV.h.

References buildFrom().

◆ ~vpHSV()

template<typename T, bool useFullScale>
virtual vpHSV< T, useFullScale >::~vpHSV ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ buildFrom() [1/11]

template<typename T, bool useFullScale>
template<typename U = T, bool otherUseFullScale>
std::enable_if< std::is_floating_point< U >::value, vpHSV< T, useFullScale > & >::type vpHSV< T, useFullScale >::buildFrom ( const vpHSV< unsigned char, otherUseFullScale > & other)
inline

Convert a vpHSV that uses unsigned char for its channels into a vpHSV that uses floating point for its channels.

Template Parameters
UThe type of the channels of the vpHSV pixels.
otherUseFullScale
typeEnable the method only if the modified object uses floating point format.
Parameters
[in]otherThe unsigned char vpHSV.
Returns
Reference to the modified object.

Definition at line 295 of file vpHSV.h.

References H, maxHueUsingLimitedRange, S, V, and vpHSV().

◆ buildFrom() [2/11]

template<typename T, bool useFullScale>
template<typename U = T, typename V, bool otherUseFullScale>
std::enable_if< std::is_floating_point< U >::value &&std::is_floating_point< V >::value &&!std::is_same< T, V >::value, vpHSV< T, useFullScale > & >::type vpHSV< T, useFullScale >::buildFrom ( const vpHSV< V, otherUseFullScale > & other)
inline

Convert a floating point HSV into another floating point type HSV.

Template Parameters
UThe type of the channels of the vpHSV pixels that is modified.
VThe type of the channels of the vpHSV pixels that serves as reference.
otherUseFullScaleTo avoid problem if one was created with true and the other false (even it is not used for floating point types).
typeEnable the method only if the modified object uses is a floating point format, the base object too but the formats are different. The type "int" is not used, it is here only because float and doubles are "not [a] valid type for a template non-type parameter"
Parameters
[in]otherThe floating point HSV.
Returns
vpHSV<T, useFullScale>& Reference to the modified object.

Definition at line 323 of file vpHSV.h.

References H, S, V, and vpHSV().

◆ buildFrom() [3/11]

template<typename T, bool useFullScale>
template<typename U = T, typename V, bool otherUseFullScale>
std::enable_if< std::is_same< U, unsignedchar >::value &&std::is_floating_point< V >::value &&!useFullScale, vpHSV< T, useFullScale > & >::type vpHSV< T, useFullScale >::buildFrom ( const vpHSV< V, otherUseFullScale > & other)
inline

Convert a floating point HSV into a unsigned char HSV using the limited range [0; maxHueUsingLimitedRange].

Template Parameters
UThe type of the channels of the vpHSV pixels that is modified.
VThe type of the channels of the vpHSV pixels that serves as reference.
typeEnable the method only if the modified object uses unsigned char and limited range [0; maxHueUsingLimitedRange] and the base object uses a floating point format.
Parameters
[in]otherThe floating point HSV.
Returns
Reference to the modified object.

Definition at line 275 of file vpHSV.h.

References H, maxHueUsingLimitedRange, S, V, and vpHSV().

◆ buildFrom() [4/11]

template<typename T, bool useFullScale>
template<typename V, bool otherUseFullScale>
std::enable_if< std::is_same< T, unsignedchar >::value &&std::is_floating_point< V >::value &&useFullScale, vpHSV< T, useFullScale > & >::type vpHSV< T, useFullScale >::buildFrom ( const vpHSV< V, otherUseFullScale > & other)
inline

Convert a floating point HSV into a unsigned char HSV using the full range [0; 255].

Template Parameters
UThe type of the channels of the vpHSV pixels that is modified.
VThe type of the channels of the vpHSV pixels that serves as reference.
typeEnable the method only if the modified object uses unsigned char and full range [0; 255] and the base object uses a floating point format.
Parameters
[in]otherThe floating point HSV.
Returns
Reference to the modified object.

Definition at line 255 of file vpHSV.h.

References H, S, V, and vpHSV().

◆ buildFrom() [5/11]

VISP_EXPORT vpHSV< double > & vpHSV< double >::buildFrom ( const vpRGBa & rgba)

References vpHSV().

◆ buildFrom() [6/11]

VISP_EXPORT vpHSV< unsigned char, true > & vpHSV< unsignedchar, true >::buildFrom ( const vpRGBa & rgba)

References vpHSV().

◆ buildFrom() [7/11]

VISP_EXPORT vpHSV< unsigned char, false > & vpHSV< unsignedchar, false >::buildFrom ( const vpRGBa & rgba)

References vpHSV().

◆ buildFrom() [8/11]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale > & vpHSV< T, useFullScale >::buildFrom ( const vpRGBa & rgba)

Modify the object to be the result of the conversion of the vpRGBa object into HSV format.

Parameters
[in]rgbaThe vpRGBa object that serves as model/
Returns
Reference to the modified object.

References vpHSV().

Referenced by vpHSV(), vpHSV(), and vpHSV().

◆ buildFrom() [9/11]

vpHSV< unsigned char, false > & vpHSV< unsignedchar, false >::buildFrom ( const vpRGBa & rgba)

Definition at line 60 of file vpHSV.cpp.

References computeNormalizedHSV(), maxHueUsingLimitedRange, and vpHSV().

◆ buildFrom() [10/11]

vpHSV< unsigned char, true > & vpHSV< unsignedchar, true >::buildFrom ( const vpRGBa & rgba)

Definition at line 48 of file vpHSV.cpp.

References computeNormalizedHSV(), and vpHSV().

◆ buildFrom() [11/11]

BEGIN_VISP_NAMESPACE vpHSV< double > & vpHSV< double >::buildFrom ( const vpRGBa & rgba)

Definition at line 40 of file vpHSV.cpp.

References computeNormalizedHSV(), and vpHSV().

◆ computeNormalizedHSV()

template<typename T, bool useFullScale>
vpColVector vpHSV< T, useFullScale >::computeNormalizedHSV ( const vpRGBa & rgba)
inlinestatic

Compute the normalized HSV values (i.e. in the range [0; 1]) that correspond to a vpRGBa object.

Parameters
[in]rgbaThe RGB pixel.
Returns
vpColVector Vector of normalized HSV values.

Definition at line 337 of file vpHSV.h.

References vpRGBa::B, vpMath::equal(), vpRGBa::G, and vpRGBa::R.

Referenced by buildFrom().

◆ mahalanobisDistance() [1/2]

template<typename T, bool useFullScale>
template<typename ArithmeticType>
ArithmeticType vpHSV< T, useFullScale >::mahalanobisDistance ( const vpHSV< T, useFullScale > & a,
const vpHSV< T, useFullScale > & b )
inlinestatic

Compute the Mahalanobis distance between two HSV pixels. It is assumed that the channels are independent and follow a uniform distribution law.

Parameters
[in]aThe first pixel to compare.
[in]bThe second pixel to compare.
Returns
float The Mahalanobis distance between a and b.

Definition at line 443 of file vpHSV.h.

References squaredMahalanobisDistance(), and vpHSV().

◆ mahalanobisDistance() [2/2]

template<typename T, bool useFullScale>
template<typename ArithmeticType>
ArithmeticType vpHSV< T, useFullScale >::mahalanobisDistance ( const vpHSV< T, useFullScale > & a,
const vpHSV< T, useFullScale > & b,
vpColVector & diff )
inlinestatic

Compute the Mahalanobis distance between two HSV pixels. It is assumed that the channels are independent and follow a uniform distribution law.

Parameters
[in]aThe first pixel to compare.
[in]bThe second pixel to compare.
[out]diffThe vector (b - a).
Returns
float The Mahalanobis distance between a and b.

Definition at line 458 of file vpHSV.h.

References squaredMahalanobisDistance(), and vpHSV().

◆ operator!=()

template<typename T, bool useFullScale>
bool vpHSV< T, useFullScale >::operator!= ( const vpHSV< T, useFullScale > & v) const
inline

Definition at line 480 of file vpHSV.h.

References vpHSV().

◆ operator+() [1/2]

template<typename T, bool useFullScale>
vpColVector vpHSV< T, useFullScale >::operator+ ( const vpColVector & v) const
inline

Definition at line 504 of file vpHSV.h.

References H, S, and V.

◆ operator+() [2/2]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale > vpHSV< T, useFullScale >::operator+ ( const vpHSV< T, useFullScale > & v) const
inline

Definition at line 490 of file vpHSV.h.

References H, S, V, and vpHSV().

◆ operator-() [1/2]

template<typename T, bool useFullScale>
vpColVector vpHSV< T, useFullScale >::operator- ( const vpColVector & v) const
inline

Definition at line 499 of file vpHSV.h.

References toColVector().

◆ operator-() [2/2]

template<typename T, bool useFullScale>
vpColVector vpHSV< T, useFullScale >::operator- ( const vpHSV< T, useFullScale > & v) const
inline

Definition at line 485 of file vpHSV.h.

References toColVector(), and vpHSV().

◆ operator=() [1/3]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale > & vpHSV< T, useFullScale >::operator= ( const vpColVector & v)
inline

Definition at line 467 of file vpHSV.h.

References vpHSV().

◆ operator=() [2/3]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale > & vpHSV< T, useFullScale >::operator= ( const vpHSV< T, useFullScale > & )
default

References vpHSV().

◆ operator=() [3/3]

template<typename T, bool useFullScale>
vpHSV< T, useFullScale > & vpHSV< T, useFullScale >::operator= ( vpHSV< T, useFullScale > && )
default

References vpHSV().

◆ operator==()

template<typename T, bool useFullScale>
bool vpHSV< T, useFullScale >::operator== ( const vpHSV< T, useFullScale > & v) const
inline

Definition at line 475 of file vpHSV.h.

References vpMath::equal(), H, S, V, and vpHSV().

◆ squaredMahalanobisDistance() [1/2]

template<typename T, bool useFullScale>
template<typename ArithmeticType>
ArithmeticType vpHSV< T, useFullScale >::squaredMahalanobisDistance ( const vpHSV< T, useFullScale > & a,
const vpHSV< T, useFullScale > & b )
inlinestatic

Compute the square of the Mahalanobis distance between two HSV pixels. It is assumed that the channels are independent and follow a uniform distribution law.

Parameters
[in]aThe first pixel to compare.
[in]bThe second pixel to compare.
Returns
float The squared Mahalanobis distance between a and b.

Definition at line 428 of file vpHSV.h.

References squaredMahalanobisDistance(), and vpHSV().

◆ squaredMahalanobisDistance() [2/2]

template<typename T, bool useFullScale>
template<typename ArithmeticType>
ArithmeticType vpHSV< T, useFullScale >::squaredMahalanobisDistance ( const vpHSV< T, useFullScale > & a,
const vpHSV< T, useFullScale > & b,
vpColVector & diff )
inlinestatic

Compute the square of the Mahalanobis distance between two HSV pixels. It is assumed that the channels are independent and follow a uniform distribution law.

Parameters
[in]aThe first pixel to compare.
[in]bThe second pixel to compare.
[out]diffThe vector (b - a).
Returns
float The squared Mahalanobis distance between a and b.

Definition at line 407 of file vpHSV.h.

References H, vpColVector::resize(), S, V, and vpHSV().

Referenced by mahalanobisDistance(), mahalanobisDistance(), and squaredMahalanobisDistance().

◆ toColVector()

template<typename T, bool useFullScale>
vpColVector vpHSV< T, useFullScale >::toColVector ( ) const
inline

Cast a vpHSV into a vpColVector.

Returns
vpColVector

Definition at line 518 of file vpHSV.h.

References H, S, and V.

Referenced by operator-(), and operator-().

◆ toString()

template<typename T, bool useFullScale>
std::string vpHSV< T, useFullScale >::toString ( ) const
virtual

Cast a vpHSV into a string, for display purpose.

Returns
std::string

Definition at line 612 of file vpHSV.h.

References H, S, and V.

Referenced by operator<<.

◆ operator<<

template<typename T, bool useFullScale>
std::ostream & operator<< ( std::ostream & os,
const vpHSV< T, useFullScale > & hsv )
friend

Definition at line 638 of file vpHSV.h.

References operator<<, toString(), and vpHSV().

Referenced by operator<<.

Member Data Documentation

◆ H

template<typename T, bool useFullScale>
T vpHSV< T, useFullScale >::H

◆ maxHueUsingLimitedRange

template<typename T, bool useFullScale>
unsigned char vpHSV< T, useFullScale >::maxHueUsingLimitedRange = 179
staticconstexpr

Maximum value of the Hue channel when using unsigned char and the limited range.

Examples
testHSVtoHSV.cpp, testHSVtoRGBa.cpp, and testRGBaToHSV.cpp.

Definition at line 549 of file vpHSV.h.

Referenced by buildFrom(), buildFrom(), and buildFrom().

◆ nbChannels

template<typename T, bool useFullScale>
unsigned char vpHSV< T, useFullScale >::nbChannels = 3
staticconstexpr

Number of channels a HSV pixel is made of.

Definition at line 544 of file vpHSV.h.

◆ S

template<typename T, bool useFullScale>
T vpHSV< T, useFullScale >::S

◆ V

template<typename T, bool useFullScale>
T vpHSV< T, useFullScale >::V