#include <CutSegment.h>
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 | |
![]() | |
enum | EDir { DIR_EAST, DIR_NORTH, DIR_WEST, DIR_SOUTH } |
![]() | |
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) |
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.
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.
References CutGrid::DIR_EAST, CutGrid::DIR_NORTH, CutGrid::DIR_SOUTH, and CutGrid::DIR_WEST.
|
virtual |
the destructor frees all the memory that was reserved for the vertices, edges and faces created by the constructor.
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.
r | red channel of the image. |
g | green channel of the image. |
b | blue 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.
stMask | a mask that assign to every pixel non-negative values. |
source | the value in stMask that describes the preselected source set. |
sink | the value in stMask that describes the preselected sink set. |
References CutGrid::setSink(), and CutGrid::setSource().
|
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|
.
|
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().