PlanarGC  1.0.2
 All Data Structures Functions Variables Enumerations Enumerator Friends Pages
CutSegment Class Reference

#include <CutSegment.h>

+ Inheritance diagram for CutSegment:

Public Member Functions

 CutSegment (int width, int height)
virtual ~CutSegment ()
void setImageData (const uchar *grey)
void setImageData (const uchar *r, const uchar *g, const uchar *b)
void setSourceSink (const uchar *stMask, uchar source, uchar sink)
virtual double gradient (double color1, double color2)
virtual double gradient (double color1[3], double color2[3])
double segment ()
CutPlanar::ELabel getLabel (int x, int y)
void getLabels (CutPlanar::ELabel *lmask)

Additional Inherited Members

- Private Types inherited from CutGrid
enum  EDir {
  DIR_EAST,
  DIR_NORTH,
  DIR_WEST,
  DIR_SOUTH
}
- Private Member Functions inherited from CutGrid
 CutGrid (int nRows, int nCols)
virtual ~CutGrid ()
void setSource (int row, int col)
void setSink (int row, int col)
void getSource (int &row, int &col)
void getSink (int &row, int &col)
void setEdgeCostFunction (CapType(*edgeCostFunc)(int row, int col, EDir dir))
virtual CapType edgeCost (int row, int col, EDir dir)
double getMaxFlow ()
CutPlanar::ELabel getLabel (int row, int col)
void getLabels (CutPlanar::ELabel *lmask)

Detailed Description

CutSegment provides an interface to compute a graph cut based image segmentation. In order to define the problem as a planar graph cut problem, we assume a 4-connected neighborhood for every pixel. In addition, the subset of pixels that are previously selected as being either part of the source or the sink set have to be connected subsets.
The edges for CutSegment are uniquely defined by the color gradient between adjacent pixels. In the case of more complex edges, we recommend to use the class CutGrid instead.

Examples:
cutsegment.cpp.

Constructor & Destructor Documentation

CutSegment::CutSegment ( int  width,
int  height 
)

the constructor creates a graph of width times height vertices and the associated faces and edges. To adapt the class to one's need, it is recommended to rewrite CutSegment::gradient for greyscale or color images.

Examples:
cutsegment.cpp.

References CutGrid::DIR_EAST, CutGrid::DIR_NORTH, CutGrid::DIR_SOUTH, and CutGrid::DIR_WEST.

CutSegment::~CutSegment ( )
virtual

the destructor frees all the memory that was reserved for the vertices, edges and faces created by the constructor.

Member Function Documentation

void CutSegment::setImageData ( const uchar *  grey)

provides the image data that should be segmented.
The data of the greyscale image is provided as an array grey of width*height pixels that are stored row-wise.

void CutSegment::setImageData ( const uchar *  r,
const uchar *  g,
const uchar *  b 
)

provides the image data that should be segmented.
The data of the RGB-image is provided as three arrays of width*height pixels that are stored row-wise.

Parameters
rred channel of the image.
ggreen channel of the image.
bblue channel of the image.
void CutSegment::setSourceSink ( const uchar *  stMask,
uchar  source,
uchar  sink 
)

defines the pixel subsets that are part of the source and the sink set.
Both, the preselected source and sink sets have to be connected. If this is not the case, the method will select one connected source component as source set and one connected sink component as sink set.

Parameters
stMaska mask that assign to every pixel non-negative values.
sourcethe value in stMask that describes the preselected source set.
sinkthe value in stMask that describes the preselected sink set.

References CutGrid::setSink(), and CutGrid::setSource().

double CutSegment::gradient ( double  color1,
double  color2 
)
virtual

computes a geodesic-active-contour like cost between two neighboring pixels. The cost depends only on the greyscale values color1 and color2 of these pixels and should be monotonically decreasing wrt to the distance |color1-color2| .

Examples:
cutsegment.cpp.
double CutSegment::gradient ( double  color1[3],
double  color2[3] 
)
virtual

computes a geodesic-active-contour like cost between two neighboring pixels. The cost depends only on the RGB values color1 and color2 of these pixels and should be monotonically decreasing wrt to the distance ||color1-color2|| .

double CutSegment::segment ( )

returns the value of the minimum energy wrt to the geodesic-active-contour like energy functional defined by gradient.

References CutGrid::getMaxFlow().

CutPlanar::ELabel CutSegment::getLabel ( int  x,
int  y 
)

returns the label of a specific pixel after segmentation.

Referenced by getLabels().

void CutSegment::getLabels ( CutPlanar::ELabel lmask)

writes the value of every pixel's label into the pre-allocated lmask. The method uses the row-wise format that was also used for the image data (see setImageData).

References getLabel().

© 2009 - 2013 by Eno Töppe, Frank R. Schmidt
generated by Doxygen