latest version v1.9 - last update 10 Apr 2010 |
The whitening segmentation is an extention of the k-Means based segmentation (see lti::kMeansSegmentation). More...
#include <ltiWhiteningSegmentation.h>
Classes | |
class | parameters |
the parameters for the class whiteningSegmentation More... | |
Public Member Functions | |
whiteningSegmentation () | |
whiteningSegmentation (const whiteningSegmentation &other) | |
virtual | ~whiteningSegmentation () |
virtual const char * | getTypeName () const |
void | attachPoints (const image &src, pointList &freePoints, imatrix &imgMap) const |
void | removeSmallRegions (const image &src, const int &thresh, imatrix &imgMap) const |
bool | transformImage (const principalComponents< float > &pca, const image &src, image &dest) const |
bool | transformImage (const drgbPixel &mean, const dmatrix &covar, const image &src, image &dest) const |
bool | apply (const image &src, const principalComponents< float > &pca, imatrix &dest) const |
bool | apply (const image &src, const drgbPixel &mean, const dmatrix &covar, imatrix &dest) const |
whiteningSegmentation & | copy (const whiteningSegmentation &other) |
whiteningSegmentation & | operator= (const whiteningSegmentation &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
The whitening segmentation is an extention of the k-Means based segmentation (see lti::kMeansSegmentation).
Internally, it computes the k-Means segmentation of the given image, and the k-Means segmentation of an image resulting from mapping linearly each RGB pixel in the original image into another color space determined by the given pca transformation functor. The mapping is clipped using a sigmoid function to keep all values in the valid RGB space (0..255 for each component). The last stage removes the smallest regions assigning their pixels to the neighbor most similar ones.
The PCA can be obtained using from example the lti::colorModelSelector, which is usually configured to returned a skin color model. The PCA is used to make a "color zoom" into the skin color to detect the borders between skin colored objects and real skin.
The two color quantization results are combined into the final one, multiplying the labels of the second segmentation by the number of labels of the first quantization, and adding the first quantization.
lti::whiteningSegmentation::whiteningSegmentation | ( | ) |
default constructor
lti::whiteningSegmentation::whiteningSegmentation | ( | const whiteningSegmentation & | other | ) |
copy constructor
other | the object to be copied |
virtual lti::whiteningSegmentation::~whiteningSegmentation | ( | ) | [virtual] |
destructor
bool lti::whiteningSegmentation::apply | ( | const image & | src, | |
const drgbPixel & | mean, | |||
const dmatrix & | covar, | |||
imatrix & | dest | |||
) | const |
operates on a copy of the given parameters.
You can get the mean and covariance matrix (which should be computed in a RGB color space with each color between 0 and 255) using the lti::colorModelEstimator functor.
src | image with the source data. | |
mean | mean color used for the pca/whitening transformation | |
covar | covariance matrix used for the pca/whitening transformation | |
dest | image where the result will be left. |
bool lti::whiteningSegmentation::apply | ( | const image & | src, | |
const principalComponents< float > & | pca, | |||
imatrix & | dest | |||
) | const |
virtual functor* lti::whiteningSegmentation::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this functor.
Reimplemented from lti::segmentation.
whiteningSegmentation& lti::whiteningSegmentation::copy | ( | const whiteningSegmentation & | other | ) |
copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::segmentation.
const parameters& lti::whiteningSegmentation::getParameters | ( | ) | const |
returns used parameters
Reimplemented from lti::functor.
virtual const char* lti::whiteningSegmentation::getTypeName | ( | ) | const [virtual] |
returns the name of this type ("whiteningSegmentation")
Reimplemented from lti::segmentation.
whiteningSegmentation& lti::whiteningSegmentation::operator= | ( | const whiteningSegmentation & | other | ) |
bool lti::whiteningSegmentation::transformImage | ( | const drgbPixel & | mean, | |
const dmatrix & | covar, | |||
const image & | src, | |||
image & | dest | |||
) | const |
whitening transformation of the src image in the dest image using the given statistical parameter to create a pca-whitening transformation.
A sigmoid clipping will be taken to limit the result to valid values in the RGB color space. This operation can be considered as color zooming.
The given parameters of mean and covariance can be computed directly with functors like the colorModelEstimator and computePalette (for this last one some type conversions would be required)
mean | drgbPixel with the mean color, that will be projected into rgbPixel(128,128,128). The coordinates of the mean should be between 0 and 255. | |
covar | a 3x3 dmatrix with the covariance matrix of the colors. | |
src | source image | |
dest | color zoomed image |
Example:
// Example for color zoom lti::image img; // original color imaged lti::image zoomed; // color zoomed image ... // get the image and the mask with any algorithm... lti::colorModelEstimator colEst; // functor used to get a color model lti::dmatrix covariance; // covariance matrix of the color lti::drgbPixel mean; // mean color // compute mean color and covariance matrix for the pixels in the given // image. colEst.consider(img); colEst.apply(mean,covariance); // compute the color zoomed image lti::whiteningSegmentation wseg; wseg.transformImage(mean,covariance,img,zoomed);
bool lti::whiteningSegmentation::transformImage | ( | const principalComponents< float > & | pca, | |
const image & | src, | |||
image & | dest | |||
) | const |
whitening transformation of the src image in the dest image using the given pca transformation functor.
A sigmoid clipping will be taken to limit the result to valid values in the RGB color space. This operation can be considered as color zooming.
For the given pca functor, it will be expected that the color axes have been normalized from 0 to 1 (instead of 0 to 255).
pca | functor with the linear transformation matrix (pca). | |
src | image | |
dest | color zoomed image |
Example:
// Example for color zoom lti::image img; // original color imaged lti::image zoomed; // color zoomed image lti::imatrix mask; // labeled mask, result of a segmentation algorithm ... // get the image and the mask with any algorithm... lti::computePalette compPal; // functor used to get a complete palette // or just a palette entry of an image // given a mask. lti::fmatrix covariance; // covariance matrix of the color lti::fvector mean; // mean color int n; // how many pixels were considered in the // computation of mean and covariance. // compute mean color and covariance matrix for the pixels with // label "0" (usually background) compPal.apply(img,mask,0,mean,covariance,n); // for the color zooming, the mean and covariance need to be // given for the unit cube color space, instead of the 8-bit valued // color space. mean.divide(255); covariance.divide(255*255); // principal components functor used to transform the pixel colors lti::principalComponents<float> pca; lti::principalComponents<float>::parameters pcaPar; pcaPar.whitening = true; // whitening transform is a requirement! pcaPar.resultDim = 3; // after the transform, each pixel must // still have three dimensions! pcaPar.autoDim = false; // do not try to reduce the dimensionality pca.setParameters(pcaPar); // specify to use the given parameters pca.setCovarianceAndMean(covariance,mean); // and the computed stats. // compute the color zoomed image lti::whiteningSegmentation wseg; wseg.transformImage(pca,img,zoomed);