Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpColorHistogram Class Reference

#include <vpColorHistogram.h>

Classes

class  Builder

Public Member Functions

 vpColorHistogram ()
 vpColorHistogram (unsigned int N)
void setBinNumber (unsigned int N)
unsigned int getBinNumber () const
unsigned int getNumPixels () const
void build (const vpImage< vpRGBa > &image, const vpImage< bool > &mask)
void build (const std::vector< unsigned int > &counts)
void merge (const vpColorHistogram &other, float alpha)
void computeProbas (const vpImage< vpRGBa > &image, vpImage< float > &proba) const
void computeProbas (const vpImage< vpRGBa > &image, vpImage< float > &proba, const vpRect &bb) const
unsigned int colorToIndex (const vpRGBa &p) const
vpRGBa indexToColor (unsigned int index) const
double probability (const vpRGBa &color) const
double kl (const vpColorHistogram &other) const
double jsd (const vpColorHistogram &other) const
double hellinger (const vpColorHistogram &other) const
std::vector< vpRGBamostLikelyColors (unsigned int N) const

Static Public Member Functions

static void computeSplitHistograms (const vpImage< vpRGBa > &image, const vpImage< bool > &mask, vpColorHistogram &inMask, vpColorHistogram &outsideMask)
static void computeSplitHistograms (const vpImage< vpRGBa > &image, const vpImage< bool > &mask, const vpRect &bbInside, vpColorHistogram &insideMask, vpColorHistogram &outsideMask)

Detailed Description

Histogram representation of an RGB color distribution In this representation, probabilities are stored in evenly sized bins. It can then be used to compute the probability of a specific color given the approximated color distribution. The number of bins N should be a power of 2.

Definition at line 56 of file vpColorHistogram.h.

Constructor & Destructor Documentation

◆ vpColorHistogram() [1/2]

vpColorHistogram::vpColorHistogram ( )

◆ vpColorHistogram() [2/2]

vpColorHistogram::vpColorHistogram ( unsigned int N)

Definition at line 57 of file vpColorHistogram.cpp.

References setBinNumber().

Member Function Documentation

◆ build() [1/2]

void vpColorHistogram::build ( const std::vector< unsigned int > & counts)

Intermediate method to build an histogram, from a vector containing the occurence counts of each color bins. The vector should have N^3 values, each corresponding to a color bin. To get the color to index correspondence, see colorToIndex.

Parameters
countsthe color occurence counts

Definition at line 91 of file vpColorHistogram.cpp.

References vpException::dimensionError.

◆ build() [2/2]

void vpColorHistogram::build ( const vpImage< vpRGBa > & image,
const vpImage< bool > & mask )

Build the histogram representation and associated color probabilities given an image and a mask. From this image, only the pixels where the mask is true will be used to create the histogram.

Parameters
imagethe input image
maskthe mask giving the pixels to use

Definition at line 73 of file vpColorHistogram.cpp.

References vpImage< Type >::bitmap, colorToIndex(), and vpImage< Type >::getSize().

Referenced by computeSplitHistograms(), and computeSplitHistograms().

◆ colorToIndex()

unsigned int vpColorHistogram::colorToIndex ( const vpRGBa & p) const
inline

Convert an RGB color to an index that can be used to retrieve the probability of this color The alpha channel is ignored.

Parameters
pthe input color
Returns
unsigned int the index used to query the histogram vector

Definition at line 146 of file vpColorHistogram.h.

Referenced by build(), computeProbas(), computeProbas(), computeSplitHistograms(), computeSplitHistograms(), and probability().

◆ computeProbas() [1/2]

void vpColorHistogram::computeProbas ( const vpImage< vpRGBa > & image,
vpImage< float > & proba ) const

Compute the probabilities of every pixel according to this histogram.

Parameters
imagethe input image
probaOutput probability map

Definition at line 124 of file vpColorHistogram.cpp.

References vpImage< Type >::bitmap, colorToIndex(), vpImage< Type >::getHeight(), vpImage< Type >::getSize(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

◆ computeProbas() [2/2]

void vpColorHistogram::computeProbas ( const vpImage< vpRGBa > & image,
vpImage< float > & proba,
const vpRect & bb ) const

Compute the probabilities of pixels according to this histogram. This version only scores the pixels in the input bounding box.

Parameters
imagethe input image
probaOutput probability map
bbThe bounding box where to score the pixels

Definition at line 135 of file vpColorHistogram.cpp.

References colorToIndex(), vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

◆ computeSplitHistograms() [1/2]

void vpColorHistogram::computeSplitHistograms ( const vpImage< vpRGBa > & image,
const vpImage< bool > & mask,
const vpRect & bbInside,
vpColorHistogram & insideMask,
vpColorHistogram & outsideMask )
static

◆ computeSplitHistograms() [2/2]

void vpColorHistogram::computeSplitHistograms ( const vpImage< vpRGBa > & image,
const vpImage< bool > & mask,
vpColorHistogram & inMask,
vpColorHistogram & outsideMask )
static

◆ getBinNumber()

unsigned int vpColorHistogram::getBinNumber ( ) const
inline

Definition at line 86 of file vpColorHistogram.h.

Referenced by vpColorHistogram::Builder::build().

◆ getNumPixels()

unsigned int vpColorHistogram::getNumPixels ( ) const
inline

Get the number of pixels used to compute this histogram. Can be useful when merging different histograms.

Returns
unsigned int

Definition at line 93 of file vpColorHistogram.h.

◆ hellinger()

double vpColorHistogram::hellinger ( const vpColorHistogram & other) const

Definition at line 180 of file vpColorHistogram.cpp.

References vpColorHistogram().

◆ indexToColor()

vpRGBa vpColorHistogram::indexToColor ( unsigned int index) const
inline

Convert an index value to a color.

Parameters
indexan index value that should be between 0 and N^3
Returns
vpRGBa a color in the bin corresponding to the index

Definition at line 156 of file vpColorHistogram.h.

References vpRGBa::A, vpRGBa::B, vpRGBa::G, and vpRGBa::R.

Referenced by mostLikelyColors().

◆ jsd()

double vpColorHistogram::jsd ( const vpColorHistogram & other) const

Definition at line 169 of file vpColorHistogram.cpp.

References kl(), and vpColorHistogram().

◆ kl()

double vpColorHistogram::kl ( const vpColorHistogram & other) const

Definition at line 155 of file vpColorHistogram.cpp.

References vpException::badValue, and vpColorHistogram().

Referenced by jsd().

◆ merge()

void vpColorHistogram::merge ( const vpColorHistogram & other,
float alpha )

Merge this histogram with an another. This histogram is modified. The probabilities are interpolated between this histogram's values and the other's.

Parameters
otherThe histogram to merge with
alphathe interpolation/importance factor of the other histogram. between 0 and 1. 1 completely replaces this histogram with other.

Definition at line 106 of file vpColorHistogram.cpp.

References vpException::badValue, and vpColorHistogram().

◆ mostLikelyColors()

std::vector< vpRGBa > vpColorHistogram::mostLikelyColors ( unsigned int N) const
inline

Get the N most likely colors according to this histogram.

Parameters
Nthe number of colors to retrieve
Returns
std::vector<vpRGBa> the most likely colors

Definition at line 191 of file vpColorHistogram.h.

References indexToColor().

◆ probability()

double vpColorHistogram::probability ( const vpRGBa & color) const
inline

Get the probability of an RGB color according to this histogram.

Parameters
colorthe color
Returns
double the estimated probability (0-1)

Definition at line 172 of file vpColorHistogram.h.

References colorToIndex().

Referenced by vpProbaComputer::vpProbaComputer().

◆ setBinNumber()

void vpColorHistogram::setBinNumber ( unsigned int N)

Change the number of bins per color component that the histogram has After calling this method, the histogram will be reset and the values will not be kept.

Parameters
Nthe number of bins per RGB component: the histogram will have N^3 bins in total. N should be a power of 2 between 1 and 128

Definition at line 62 of file vpColorHistogram.cpp.

References vpException::badValue.

Referenced by vpColorHistogram().