ViSP
2.9.0
|
#include <vpHistogram.h>
Public Member Functions | |
vpHistogram () | |
vpHistogram (const vpHistogram &h) | |
vpHistogram (const vpImage< unsigned char > &I) | |
virtual | ~vpHistogram () |
vpHistogram & | operator= (const vpHistogram &h) |
unsigned | operator[] (const unsigned char level) const |
unsigned | operator() (const unsigned char level) const |
unsigned | get (const unsigned char level) const |
void | set (const unsigned char level, unsigned int value) |
void | calculate (const vpImage< unsigned char > &I) |
void | smooth (const unsigned int fsize=3) |
unsigned | getPeaks (std::list< vpHistogramPeak > &peaks) |
unsigned | getPeaks (unsigned char dist, vpHistogramPeak &peak1, vpHistogramPeak &peak2) |
bool | getPeaks (unsigned char dist, vpHistogramPeak &peakl, vpHistogramPeak &peakr, vpHistogramValey &valey) |
unsigned | getValey (std::list< vpHistogramValey > &valey) |
bool | getValey (const vpHistogramPeak &peak1, const vpHistogramPeak &peak2, vpHistogramValey &valey) |
unsigned | getValey (unsigned char dist, const vpHistogramPeak &peak, vpHistogramValey &valeyl, vpHistogramValey &valeyr) |
unsigned | sort (std::list< vpHistogramPeak > &peaks) |
bool | write (const std::string &filename) |
bool | write (const char *filename) |
unsigned | getSize () |
unsigned * | getValues () |
Deprecated functions | |
vp_deprecated unsigned | getPeaks (vpList< vpHistogramPeak > &peaks) |
vp_deprecated unsigned | getValey (vpList< vpHistogramValey > &valey) |
vp_deprecated unsigned | sort (vpList< vpHistogramPeak > &peaks) |
Class to compute a gray level image histogram.
Here are two examples showing how to use this class to determine the threshold which can be used to segment two objects.
The code below:
has the same behaviour than this one:
Definition at line 115 of file vpHistogram.h.
vpHistogram::vpHistogram | ( | ) |
Defaut constructor for a gray level histogram.
Definition at line 68 of file vpHistogram.cpp.
vpHistogram::vpHistogram | ( | const vpHistogram & | h | ) |
Copy constructor of a gray level histogram.
Definition at line 76 of file vpHistogram.cpp.
vpHistogram::vpHistogram | ( | const vpImage< unsigned char > & | I | ) |
Calculates the histrogram from a gray level image.
I | : Gray level image. |
Definition at line 89 of file vpHistogram.cpp.
References calculate().
|
virtual |
Destructor.
Definition at line 100 of file vpHistogram.cpp.
void vpHistogram::calculate | ( | const vpImage< unsigned char > & | I | ) |
Calculate the histogram from a gray level image.
I | : Gray level image. |
Definition at line 161 of file vpHistogram.cpp.
References vpImage< Type >::getHeight(), and vpImage< Type >::getWidth().
Referenced by vpHistogram().
|
inline |
Return the number of pixels having the gray level.
level | : Gray level in the histogram. |
Definition at line 194 of file vpHistogram.h.
unsigned vpHistogram::getPeaks | ( | std::list< vpHistogramPeak > & | peaks | ) |
Build a list of all histogram peaks. This peak list is gray level sorted from 0 to 255. That mean that the first peak has a gray level less than the second one, etc.
To sort this list from highest peak value to the lowest one, you can use sort().
peaks | : List of peaks. |
Definition at line 237 of file vpHistogram.cpp.
References vpImageException::notInitializedError, vpHistogramPeak::set(), and vpERROR_TRACE.
Referenced by getPeaks(), and getValey().
unsigned vpHistogram::getPeaks | ( | unsigned char | dist, |
vpHistogramPeak & | peak1, | ||
vpHistogramPeak & | peak2 | ||
) |
Find the two highest peaks in the histogram. Usually, the first one correspond to the image background, the second one to the object.
dist | : Minimal distance between two significative histogram peaks. |
peak1 | : Highest peak in the histogram. |
peak2 | : Second highest peak in the histogram. |
Definition at line 319 of file vpHistogram.cpp.
References vpHistogramPeak::getLevel(), getPeaks(), vpHistogramPeak::set(), and sort().
bool vpHistogram::getPeaks | ( | unsigned char | dist, |
vpHistogramPeak & | peakl, | ||
vpHistogramPeak & | peakr, | ||
vpHistogramValey & | valey | ||
) |
Determine the two highest peaks in the histogram and compute a threshold to separate the two objects. Here we dont know which is the highest peak. It could be peakl or peakr.
dist | : Distance between two significative histogram maxima |
peakl | : Position of the left histogram peak. |
peakr | : Position of the right histogram peak. |
valey | : Valey between the two peaks peakl and peakr. |
Definition at line 376 of file vpHistogram.cpp.
References vpHistogramPeak::getLevel(), vpHistogramPeak::getValue(), vpHistogramPeak::set(), and vpHistogramValey::set().
unsigned vpHistogram::getPeaks | ( | vpList< vpHistogramPeak > & | peaks | ) |
Build a list of all histogram peaks. This peak list is gray level sorted from 0 to 255. That mean that the first peak has a gray level less than the second one, etc.
To sort this list from highest peak value to the lowest one, you can use sort().
peaks | : List of peaks. |
Definition at line 922 of file vpHistogram.cpp.
References vpList< type >::addRight(), vpList< type >::empty(), vpList< type >::front(), vpList< type >::kill(), vpImageException::notInitializedError, vpHistogramPeak::set(), and vpERROR_TRACE.
|
inline |
Get the histogram size.
Definition at line 252 of file vpHistogram.h.
unsigned vpHistogram::getValey | ( | std::list< vpHistogramValey > & | valey | ) |
Build a list of all histogram valey. This valey list is gray level sorted from 0 to 255. That mean that the first valey has a gray level less than the second one, etc.
valey | : List of valey. |
Definition at line 536 of file vpHistogram.cpp.
References vpImageException::notInitializedError, vpHistogramValey::set(), and vpERROR_TRACE.
bool vpHistogram::getValey | ( | const vpHistogramPeak & | peak1, |
const vpHistogramPeak & | peak2, | ||
vpHistogramValey & | valey | ||
) |
Find the valey between two peaks. It starts at the lowest peak and works its way up to the highest peak. Along the way, it looks at each point in the histogram to find the location of the smallest histogram point which is the valey point.
peak1 | : A peak in the histogram. |
peak2 | : A other peak in the histogram. |
valey | : Low point of the valey between two peaks in a histogram. |
Definition at line 609 of file vpHistogram.cpp.
References vpHistogramPeak::getLevel(), vpHistogramPeak::getValue(), and vpHistogramValey::set().
unsigned vpHistogram::getValey | ( | unsigned char | dist, |
const vpHistogramPeak & | peak, | ||
vpHistogramValey & | valeyl, | ||
vpHistogramValey & | valeyr | ||
) |
Find the two valey around an histogram peak. It starts at the peak position and works its way down and up to find the left and right valey around the peak.
dist | : Minimal distance between two significative histogram peaks. |
peak | : A peak in the histogram. |
valeyl | : The valey on the left of the peak. |
valeyr | : The valey on the right of the peak. |
Definition at line 678 of file vpHistogram.cpp.
References vpHistogramPeak::getLevel(), getPeaks(), vpHistogramPeak::getValue(), vpHistogramPeak::set(), and vpHistogramValey::set().
unsigned vpHistogram::getValey | ( | vpList< vpHistogramValey > & | valey | ) |
Build a list of all histogram valey. This valey list is gray level sorted from 0 to 255. That mean that the first valey has a gray level less than the second one, etc.
valey | : List of valey. |
Definition at line 1003 of file vpHistogram.cpp.
References vpList< type >::addRight(), vpList< type >::empty(), vpList< type >::front(), vpList< type >::kill(), vpImageException::notInitializedError, vpHistogramValey::set(), and vpERROR_TRACE.
|
inline |
Get the histogram values.
Definition at line 278 of file vpHistogram.h.
|
inline |
Return the number of pixels having the gray level.
level | : Gray level in the histogram. |
Definition at line 170 of file vpHistogram.h.
vpHistogram & vpHistogram::operator= | ( | const vpHistogram & | h | ) |
|
inline |
Return the number of pixels having the gray level.
level | : Gray level in the histogram. |
Definition at line 145 of file vpHistogram.h.
|
inline |
Set the number of pixels having the gray level.
level | : Gray level in the histogram. Level is in [0:255] |
value | : Number of pixels having the gray level. |
Definition at line 216 of file vpHistogram.h.
void vpHistogram::smooth | ( | const unsigned int | fsize = 3 | ) |
Smoothes the histogram and returns it.
A simple average scheme is used where each value in the histogram is replaced by the average of itself and the neighbours.
fsize | : Filter size. Corresponds to the number of values around each point used to compute the mean value. |
vpImageException::notInitializedError | : Histogram array not initialsed. Means that the histogram was not calculated before. |
Definition at line 193 of file vpHistogram.cpp.
References vpImageException::notInitializedError, and vpERROR_TRACE.
unsigned vpHistogram::sort | ( | std::list< vpHistogramPeak > & | peaks | ) |
Sort a list of histogram peaks from highest to the lowest.
peaks | : List of histogram peaks. |
Definition at line 848 of file vpHistogram.cpp.
Referenced by getPeaks().
unsigned vpHistogram::sort | ( | vpList< vpHistogramPeak > & | peaks | ) |
Sort a list of histogram peaks from highest to the lowest.
peaks | : List of histogram peaks. |
Definition at line 1074 of file vpHistogram.cpp.
References vpList< type >::addLeft(), vpList< type >::addRight(), vpList< type >::empty(), vpList< type >::front(), vpHistogramPeak::getValue(), vpList< type >::kill(), vpList< type >::next(), vpList< type >::nextOutside(), vpList< type >::outside(), and vpList< type >::value().
bool vpHistogram::write | ( | const std::string & | filename | ) |
Write the histogram values in a file.
In the file, on each line you will find first the gray level and than the number of pixels which have this gray level.
filename | : File name to write with histogram values. |
Definition at line 873 of file vpHistogram.cpp.
bool vpHistogram::write | ( | const char * | filename | ) |
Write the histogram values in a file.
In the file, on each line you will find first the gray level and than the number of pixels which have this gray level.
filename | : File name to write with histogram values. |
Definition at line 891 of file vpHistogram.cpp.