This class is some sort of self organizing map used for clustering. More...
#include <Beobot/ImageSpring.H>
Public Member Functions | |
ImageSpring (const int width, const int height, const int nbNeighbors) | |
Constructor that only allocates memory for given size. | |
ImageSpring () | |
Constructor for uninitialized image (useful for arrays of Images). | |
ImageSpring (const ImageSpring< T > &A) | |
Copy constructor. | |
void | init (const int width, const int height, const int nbNeighbors) |
init function | |
void | init (const T *a, const float *posX, const float *posY, const float **stiff, const int width, const int height, const int nbNeighbors) |
init function, to copy another ImageSpring | |
~ImageSpring () | |
Destructor. | |
void | freeMem () |
Free memory and switch to uninitialized state. | |
void | initClustering (bool initPosMasses) |
initialize 'stiff' and 'pos' | |
void | computeStiff (void) |
compute the stiffness of the spring between the masses | |
void | computePos (const float dt) |
updates the positions of the masses | |
void | getStats (void) |
computes mean and stdev (**heuristic**) | |
void | getStatsDist (void) |
computes meanDist and stdevDist (**heuristic**) | |
void | getXY (const int index, Point2D< int > &pt) const |
returns (X,Y) given an index=X+w*Y (see posX) | |
void | getIndex (const Point2D< int > point, int &index) const |
returns the index=X+w*Y (see posX) | |
int | getNbNeighbors (void) const |
returns the number of neighbors | |
float | getDistanceMasses (const int index1, const int index2) const |
distance between the 2 masses | |
bool | getNeighbor (const int index, const int n, int &indexNeighbor) const |
computes the index of the nth neighbor of "index" | |
void | getPositions (Image< PixRGB< byte > > &img, const int zoom=16) |
Get position of masses and strength of springs (for debug). | |
void | getClusteredImage (const Image< PixRGB< byte > > &scene, Image< PixRGB< byte > > &clusteredImage, Point2D< int > &supposedTrackCentroid, const Point2D< int > &previousTrackCentroid) |
get clustered image and track centroid position |
This class is some sort of self organizing map used for clustering.
All the pixels are linked by springs whose stiffness depends on the difference between them
Definition at line 53 of file ImageSpring.H.
ImageSpring< T >::ImageSpring | ( | const int | width, | |
const int | height, | |||
const int | nbNeighbors | |||
) | [inline] |
Constructor that only allocates memory for given size.
Definition at line 197 of file ImageSpring.H.
References ImageSpring< T >::init().
ImageSpring< T >::ImageSpring | ( | ) | [inline] |
Constructor for uninitialized image (useful for arrays of Images).
Use init() later to initialize
Definition at line 206 of file ImageSpring.H.
ImageSpring< T >::ImageSpring | ( | const ImageSpring< T > & | A | ) | [inline] |
Copy constructor.
Definition at line 211 of file ImageSpring.H.
References ASSERT, Image< T >::getArrayPtr(), Image< T >::getHeight(), Image< T >::getWidth(), ImageSpring< T >::init(), and Image< T >::initialized().
ImageSpring< T >::~ImageSpring | ( | ) | [inline] |
void ImageSpring< T >::computePos | ( | const float | dt | ) | [inline] |
updates the positions of the masses
based on simple mechanics
Definition at line 172 of file ImageSpring.C.
References gamma(), Image< T >::getHeight(), ImageSpring< T >::getIndex(), ImageSpring< T >::getNeighbor(), Image< T >::getSize(), Image< T >::getWidth(), and Y.
Referenced by BeobotVisualCortex::iterateSprings().
void ImageSpring< T >::computeStiff | ( | void | ) | [inline] |
compute the stiffness of the spring between the masses
based on the color-distance between pixels
Definition at line 139 of file ImageSpring.C.
References distance(), ImageSpring< T >::getNeighbor(), Image< T >::getSize(), Image< T >::getVal(), and ImageSpring< T >::getXY().
Referenced by ImageSpring< T >::initClustering().
void ImageSpring< T >::freeMem | ( | ) | [inline] |
Free memory and switch to uninitialized state.
Reimplemented from Image< T >.
Definition at line 227 of file ImageSpring.H.
References Image< T >::getSize().
Referenced by ImageSpring< T >::init(), and ImageSpring< T >::~ImageSpring().
void ImageSpring< T >::getClusteredImage | ( | const Image< PixRGB< byte > > & | scene, | |
Image< PixRGB< byte > > & | clusteredImage, | |||
Point2D< int > & | supposedTrackCentroid, | |||
const Point2D< int > & | previousTrackCentroid | |||
) | [inline] |
get clustered image and track centroid position
Definition at line 289 of file ImageSpring.C.
References drawCross(), Image< T >::getDims(), Image< T >::getHeight(), Image< T >::getVal(), Image< T >::getWidth(), Point2D< T >::i, max(), NO_INIT, PixRGB< T >::set(), sqrt(), squareOf(), and ZEROS.
Referenced by BeobotVisualCortex::getClusteredImage().
float ImageSpring< T >::getDistanceMasses | ( | const int | index1, | |
const int | index2 | |||
) | const [inline] |
distance between the 2 masses
Definition at line 220 of file ImageSpring.C.
References sqrt(), and squareOf().
void ImageSpring< T >::getIndex | ( | const Point2D< int > | point, | |
int & | index | |||
) | const [inline] |
returns the index=X+w*Y (see posX)
Definition at line 293 of file ImageSpring.H.
References Image< T >::getWidth(), and Point2D< T >::i.
Referenced by ImageSpring< T >::computePos(), and ImageSpring< T >::getNeighbor().
int ImageSpring< T >::getNbNeighbors | ( | void | ) | const [inline] |
returns the number of neighbors
Definition at line 351 of file ImageSpring.H.
bool ImageSpring< T >::getNeighbor | ( | const int | index, | |
const int | n, | |||
int & | indexNeighbor | |||
) | const [inline] |
computes the index of the nth neighbor of "index"
returns true iif the neighbor is in the image
Definition at line 298 of file ImageSpring.H.
References ASSERT, Image< T >::coordsOk(), ImageSpring< T >::getIndex(), ImageSpring< T >::getXY(), and Point2D< T >::i.
Referenced by ImageSpring< T >::computePos(), ImageSpring< T >::computeStiff(), ImageSpring< T >::getPositions(), and ImageSpring< T >::getStatsDist().
void ImageSpring< T >::getPositions | ( | Image< PixRGB< byte > > & | img, | |
const int | zoom = 16 | |||
) | [inline] |
Get position of masses and strength of springs (for debug).
Definition at line 225 of file ImageSpring.C.
References drawDisk(), Image< T >::getHeight(), ImageSpring< T >::getNeighbor(), Image< T >::getSize(), and Image< T >::getWidth().
Referenced by BeobotVisualCortex::getPositions().
void ImageSpring< T >::getStats | ( | void | ) | [inline] |
computes mean and stdev (**heuristic**)
this function is a heuristic because it will only consider nbHeuristic pixels at random
Definition at line 57 of file ImageSpring.C.
References ASSERT, Image< T >::getSize(), Image< T >::getVal(), Image< T >::initialized(), inplaceRectify(), inplaceSquare(), inverse(), randomUpToNotIncluding(), and sqrt().
Referenced by ImageSpring< T >::initClustering().
void ImageSpring< T >::getStatsDist | ( | void | ) | [inline] |
computes meanDist and stdevDist (**heuristic**)
weight must be defined this function is an heuristic because it will only consider nbHeuristic pairs of pixels at random
Definition at line 88 of file ImageSpring.C.
References ASSERT, distance(), ImageSpring< T >::getNeighbor(), Image< T >::getSize(), Image< T >::getVal(), Image< T >::initialized(), randomUpToNotIncluding(), sqrt(), and squareOf().
Referenced by ImageSpring< T >::initClustering().
void ImageSpring< T >::getXY | ( | const int | index, | |
Point2D< int > & | pt | |||
) | const [inline] |
returns (X,Y) given an index=X+w*Y (see posX)
Definition at line 288 of file ImageSpring.H.
References Image< T >::getWidth(), and Point2D< T >::i.
Referenced by ImageSpring< T >::computeStiff(), and ImageSpring< T >::getNeighbor().
void ImageSpring< T >::init | ( | const T * | a, | |
const float * | posX, | |||
const float * | posY, | |||
const float ** | stiff, | |||
const int | width, | |||
const int | height, | |||
const int | nbNeighbors | |||
) | [inline] |
init function, to copy another ImageSpring
Definition at line 242 of file ImageSpring.H.
References ImageSpring< T >::freeMem(), Image< T >::getSize(), Image< T >::resize(), and Image< T >::size().
void ImageSpring< T >::init | ( | const int | width, | |
const int | height, | |||
const int | nbNeighbors | |||
) | [inline] |
init function
Definition at line 270 of file ImageSpring.H.
References ImageSpring< T >::freeMem(), Image< T >::getSize(), Image< T >::resize(), and Image< T >::size().
Referenced by ImageSpring< T >::ImageSpring(), and BeobotVisualCortex::init().
void ImageSpring< T >::initClustering | ( | bool | initPosMasses | ) | [inline] |
initialize 'stiff' and 'pos'
Definition at line 121 of file ImageSpring.C.
References ImageSpring< T >::computeStiff(), Image< T >::getHeight(), Image< T >::getSize(), ImageSpring< T >::getStats(), ImageSpring< T >::getStatsDist(), and Image< T >::getWidth().
Referenced by BeobotVisualCortex::initSprings().