35#ifndef VP_COLOR_HISTOGRAM_H
36#define VP_COLOR_HISTOGRAM_H
38#include <visp3/core/vpConfig.h>
39#include <visp3/core/vpRGBa.h>
63 Builder(
unsigned int N) : m_counts(N *N *N, 0), m_N(N), m_binSize(256 / N) { }
66 unsigned int index = (color.R / m_binSize) * (m_N * m_N) + (color.G / m_binSize) * m_N + (color.B / m_binSize);
71 std::vector<unsigned int> m_counts;
72 unsigned int m_N, m_binSize;
84 void setBinNumber(
unsigned int N);
111 void build(
const std::vector<unsigned int> &counts);
148 return (p.R / m_binSize) * (m_N * m_N) + (p.G / m_binSize) * m_N + (p.B / m_binSize);
159 c.
R = (index / (m_N * m_N)) * m_binSize;
160 c.
G = ((index / m_N) % (m_N)) * m_binSize;
161 c.
B = (index % m_N) * m_binSize;
193 std::vector<size_t> bestIndices(N);
194 std::vector<size_t> idx(m_probas.size());
195 std::iota(idx.begin(), idx.end(), 0);
196 std::partial_sort_copy(
197 idx.begin(), idx.end(),
198 bestIndices.begin(), bestIndices.end(),
199 [*
this](
size_t i1,
size_t i2) {return m_probas[i1] > m_probas[i2]; }
202 std::vector<vpRGBa> colors(N);
203 for (
unsigned int i = 0; i < N; ++i) {
204 colors[i] =
indexToColor(
static_cast<unsigned int>(bestIndices[i]));
213 unsigned int m_binSize;
215 std::vector<float> m_probas;
217 unsigned int m_numPixels;
void add(const vpRGBa &color)
Histogram representation of an RGB color distribution In this representation, probabilities are store...
unsigned int getNumPixels() const
Get the number of pixels used to compute this histogram. Can be useful when merging different histogr...
double probability(const vpRGBa &color) const
Get the probability of an RGB color according to this histogram.
void build(const vpImage< vpRGBa > &image, const vpImage< bool > &mask)
Build the histogram representation and associated color probabilities given an image and a mask....
unsigned int getBinNumber() const
vpRGBa indexToColor(unsigned int index) const
Convert an index value to a color.
std::vector< vpRGBa > mostLikelyColors(unsigned int N) const
Get the N most likely colors according to this histogram.
unsigned int colorToIndex(const vpRGBa &p) const
Convert an RGB color to an index that can be used to retrieve the probability of this color The alpha...
Definition of the vpImage class member functions.
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
unsigned char A
Additional component.
Defines a rectangle in the plane.