LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::whiteningSegmentation Class Reference

The whitening segmentation is an extention of the k-Means based segmentation (see lti::kMeansSegmentation). More...

#include <ltiWhiteningSegmentation.h>

Inheritance diagram for lti::whiteningSegmentation:
Inheritance graph
[legend]
Collaboration diagram for lti::whiteningSegmentation:
Collaboration graph
[legend]

List of all members.

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
whiteningSegmentationcopy (const whiteningSegmentation &other)
whiteningSegmentationoperator= (const whiteningSegmentation &other)
virtual functorclone () const
const parametersgetParameters () const

Detailed Description

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.

Warning:
The RGB color space used is the unit cube (red, green and blue components between zero and one) and not the 8-bit based color cube, so, if you use lti::colorModelEstimator or lti::computePalette to compute a statistic color model be sure that you norm the estimated mean and covariance accordingly: mean.divide(255) and covariance.divide(255*255)! For an example see transformImage()

Constructor & Destructor Documentation

lti::whiteningSegmentation::whiteningSegmentation (  ) 

default constructor

lti::whiteningSegmentation::whiteningSegmentation ( const whiteningSegmentation other  ) 

copy constructor

Parameters:
other the object to be copied
virtual lti::whiteningSegmentation::~whiteningSegmentation (  )  [virtual]

destructor


Member Function Documentation

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.

Parameters:
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.
Returns:
true if apply successful or false otherwise.
bool lti::whiteningSegmentation::apply ( const image src,
const principalComponents< float > &  pca,
imatrix dest 
) const

operates on a copy of the given parameters.

Parameters:
src image with the source data.
pca functor responsible for the color zooming
dest image where the result will be left.
Returns:
true if apply successful or false otherwise.
void lti::whiteningSegmentation::attachPoints ( const image src,
pointList freePoints,
imatrix imgMap 
) const

attaches all pixel given by the freePoints list to a neighbour region (same label) by checking the color distances (freePoint to all its neighbours)

Parameters:
src original image
freePoints list of points to be reassigned
imgMap the image regions map
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.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

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  ) 

alias for copy member

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::functor.

void lti::whiteningSegmentation::removeSmallRegions ( const image src,
const int &  thresh,
imatrix imgMap 
) const

removes small regions from label image imgMap.

All pixels belong to a region which consist less than thresh pixels are attached to a neighbour region.

Parameters:
src original image
thresh minimal valid value for the size of a region
imgMap the image regions map
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)

See also:
transformImage(const principalComponents<float>&,const image&, image&)
Parameters:
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).

See also:
transformImage(const drgbPixel&,const dmatrix&,const image&,image&)
Parameters:
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);

The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:27:58 2010 for LTI-Lib by Doxygen 1.6.1