point_cloud_library / 1.12.1 / classpcl_1_1_grab_cut.html /

Implementation of the GrabCut segmentation in "GrabCut — Interactive Foreground Extraction using Iterated Graph Cuts" by Carsten Rother, Vladimir Kolmogorov and Andrew Blake. More...

#include <pcl/segmentation/grabcut_segmentation.h>

Classes

struct NLinks

Public Types

using KdTree = pcl::search::Search< PointT >
using KdTreePtr = typename KdTree::Ptr
using PointCloudConstPtr = typename PCLBase< PointT >::PointCloudConstPtr
using PointCloudPtr = typename PCLBase< PointT >::PointCloudPtr
- Public Types inherited from pcl::PCLBase< PointT >
using PointCloud = pcl::PointCloud< PointT >
using PointCloudPtr = typename PointCloud::Ptr
using PointCloudConstPtr = typename PointCloud::ConstPtr
using PointIndicesPtr = PointIndices::Ptr
using PointIndicesConstPtr = PointIndices::ConstPtr

Public Member Functions

GrabCut (std::uint32_t K=5, float lambda=50.f)
Constructor. More...
~GrabCut ()
Destructor. More...
void setInputCloud (const PointCloudConstPtr &cloud) override
Provide a pointer to the input dataset. More...
void setBackgroundPoints (const PointCloudConstPtr &background_points)
Set background points, foreground points = points \ background points. More...
void setBackgroundPointsIndices (int x1, int y1, int x2, int y2)
Set background indices, foreground indices = indices \ background indices. More...
void setBackgroundPointsIndices (const PointIndicesConstPtr &indices)
Set background indices, foreground indices = indices \ background indices. More...
virtual void refine ()
Run Grabcut refinement on the hard segmentation. More...
virtual int refineOnce ()
float getLambda ()
void setLambda (float lambda)
Set lambda parameter to user given value. More...
std::uint32_t getK ()
void setK (std::uint32_t K)
Set K parameter to user given value. More...
void setSearchMethod (const KdTreePtr &tree)
Provide a pointer to the search object. More...
KdTreePtr getSearchMethod ()
Get a pointer to the search method used. More...
void setNumberOfNeighbours (int nb_neighbours)
Allows to set the number of neighbours to find. More...
int getNumberOfNeighbours () const
Returns the number of neighbours to find. More...
void extract (std::vector< pcl::PointIndices > &clusters)
This method launches the segmentation algorithm and returns the clusters that were obtained during the segmentation. More...
- Public Member Functions inherited from pcl::PCLBase< PointT >
PCLBase ()
Empty constructor. More...
PCLBase (const PCLBase &base)
Copy constructor. More...
virtual ~PCLBase ()=default
Destructor. More...
const PointCloudConstPtr getInputCloud () const
Get a pointer to the input point cloud dataset. More...
virtual void setIndices (const IndicesPtr &indices)
Provide a pointer to the vector of indices that represents the input data. More...
virtual void setIndices (const IndicesConstPtr &indices)
Provide a pointer to the vector of indices that represents the input data. More...
virtual void setIndices (const PointIndicesConstPtr &indices)
Provide a pointer to the vector of indices that represents the input data. More...
virtual void setIndices (std::size_t row_start, std::size_t col_start, std::size_t nb_rows, std::size_t nb_cols)
Set the indices for the points laying within an interest region of the point cloud. More...
IndicesPtr getIndices ()
Get a pointer to the vector of indices used. More...
const IndicesConstPtr getIndices () const
Get a pointer to the vector of indices used. More...
const PointT & operator[] (std::size_t pos) const
Override PointCloud operator[] to shorten code. More...

Protected Types

using vertex_descriptor = pcl::segmentation::grabcut::BoykovKolmogorov::vertex_descriptor

Protected Member Functions

bool initCompute ()
void computeBetaOrganized ()
Compute beta from image. More...
void computeBetaNonOrganized ()
Compute beta from cloud. More...
void computeL ()
Compute L parameter from given lambda. More...
void computeNLinksOrganized ()
Compute NLinks from image. More...
void computeNLinksNonOrganized ()
Compute NLinks from cloud. More...
void setTrimap (const PointIndicesConstPtr &indices, segmentation::grabcut::TrimapValue t)
Edit Trimap. More...
int updateHardSegmentation ()
virtual void fitGMMs ()
Fit Gaussian Multi Models. More...
void initGraph ()
Build the graph for GraphCut. More...
void addEdge (vertex_descriptor v1, vertex_descriptor v2, float capacity, float rev_capacity)
Add an edge to the graph, graph must be oriented so we add the edge and its reverse. More...
void setTerminalWeights (vertex_descriptor v, float source_capacity, float sink_capacity)
Set the weights of SOURCE --> v and v --> SINK. More...
bool isSource (vertex_descriptor v)
- Protected Member Functions inherited from pcl::PCLBase< PointT >
bool initCompute ()
This method should get called before starting the actual computation. More...
bool deinitCompute ()
This method should get called after finishing the actual computation. More...

Protected Attributes

std::uint32_t width_
image width More...
std::uint32_t height_
image height More...
std::uint32_t K_
Number of GMM components. More...
float lambda_
lambda = 50. This value was suggested the GrabCut paper. More...
float beta_
beta = 1/2 * average of the squared color distances between all pairs of 8-neighboring pixels. More...
float L_
L = a large value to force a pixel to be foreground or background. More...
KdTreePtr tree_
Pointer to the spatial search object. More...
int nb_neighbours_
Number of neighbours. More...
bool initialized_
is segmentation initialized More...
std::vector< NLinks > n_links_
Precomputed N-link weights. More...
segmentation::grabcut::Image::Ptr image_
Converted input. More...
std::vector< segmentation::grabcut::TrimapValue > trimap_
std::vector< std::size_t > GMM_component_
std::vector< segmentation::grabcut::SegmentationValue > hard_segmentation_
std::vector< float > soft_segmentation_
segmentation::grabcut::GMM background_GMM_
segmentation::grabcut::GMM foreground_GMM_
pcl::segmentation::grabcut::BoykovKolmogorov graph_
Graph for Graphcut. More...
std::vector< vertex_descriptor > graph_nodes_
Graph nodes. More...
- Protected Attributes inherited from pcl::PCLBase< PointT >
PointCloudConstPtr input_
The input point cloud dataset. More...
IndicesPtr indices_
A pointer to the vector of point indices to use. More...
bool use_indices_
Set to true if point indices are used. More...
bool fake_indices_
If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. More...

Detailed Description

template<typename PointT>
class pcl::GrabCut< PointT >

Implementation of the GrabCut segmentation in "GrabCut — Interactive Foreground Extraction using Iterated Graph Cuts" by Carsten Rother, Vladimir Kolmogorov and Andrew Blake.

Author
Justin Talbot, jtalb.nosp@m.ot@s.nosp@m.tanfo.nosp@m.rd.e.nosp@m.du placed in Public Domain, 2010
Nizar Sallem port to PCL and adaptation of original code.

Definition at line 320 of file grabcut_segmentation.h.

Member Typedef Documentation

KdTree

template<typename PointT >
using pcl::GrabCut< PointT >::KdTree = pcl::search::Search<PointT>

Definition at line 323 of file grabcut_segmentation.h.

KdTreePtr

template<typename PointT >
using pcl::GrabCut< PointT >::KdTreePtr = typename KdTree::Ptr

Definition at line 324 of file grabcut_segmentation.h.

PointCloudConstPtr

template<typename PointT >
using pcl::GrabCut< PointT >::PointCloudConstPtr = typename PCLBase<PointT>::PointCloudConstPtr

Definition at line 325 of file grabcut_segmentation.h.

PointCloudPtr

template<typename PointT >
using pcl::GrabCut< PointT >::PointCloudPtr = typename PCLBase<PointT>::PointCloudPtr

Definition at line 326 of file grabcut_segmentation.h.

vertex_descriptor

Definition at line 411 of file grabcut_segmentation.h.

Constructor & Destructor Documentation

GrabCut()

template<typename PointT >
pcl::GrabCut< PointT >::GrabCut ( std::uint32_t K = 5,
float lambda = 50.f
)
inline

Constructor.

Definition at line 332 of file grabcut_segmentation.h.

~GrabCut()

template<typename PointT >
pcl::GrabCut< PointT >::~GrabCut ( )
inline

Destructor.

Definition at line 339 of file grabcut_segmentation.h.

Member Function Documentation

addEdge()

template<typename PointT >
void pcl::GrabCut< PointT >::addEdge ( vertex_descriptor v1,
vertex_descriptor v2,
float capacity,
float rev_capacity
)
protected

Add an edge to the graph, graph must be oriented so we add the edge and its reverse.

Definition at line 150 of file grabcut_segmentation.hpp.

computeBetaNonOrganized()

computeBetaOrganized()

computeL()

template<typename PointT >
void pcl::GrabCut< PointT >::computeL
protected

Compute L parameter from given lambda.

Definition at line 496 of file grabcut_segmentation.hpp.

computeNLinksNonOrganized()

template<typename PointT >
void pcl::GrabCut< PointT >::computeNLinksNonOrganized
protected

computeNLinksOrganized()

template<typename PointT >
void pcl::GrabCut< PointT >::computeNLinksOrganized
protected

extract()

template<typename PointT >
void pcl::GrabCut< PointT >::extract ( std::vector< pcl::PointIndices > & clusters )

This method launches the segmentation algorithm and returns the clusters that were obtained during the segmentation.

The indices of points belonging to the object will be stored in the cluster with index 1, other indices will be stored in the cluster with index 0.

Parameters
[out] clusters clusters that were obtained. Each cluster is an array of point indices.

Definition at line 502 of file grabcut_segmentation.hpp.

References pcl::segmentation::grabcut::SegmentationForeground.

fitGMMs()

template<typename PointT >
void pcl::GrabCut< PointT >::fitGMMs
protectedvirtual

Fit Gaussian Multi Models.

Definition at line 185 of file grabcut_segmentation.hpp.

References pcl::segmentation::grabcut::buildGMMs().

getK()

template<typename PointT >
std::uint32_t pcl::GrabCut< PointT >::getK ( )
inline
Returns
the number of components in the GMM

Definition at line 368 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::K_.

getLambda()

template<typename PointT >
float pcl::GrabCut< PointT >::getLambda ( )
inline
Returns
lambda

Definition at line 360 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::lambda_.

getNumberOfNeighbours()

template<typename PointT >
int pcl::GrabCut< PointT >::getNumberOfNeighbours ( ) const
inline

Returns the number of neighbours to find.

Definition at line 389 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::nb_neighbours_.

getSearchMethod()

template<typename PointT >
KdTreePtr pcl::GrabCut< PointT >::getSearchMethod ( )
inline

Get a pointer to the search method used.

Definition at line 381 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::tree_.

initCompute()

template<typename PointT >
bool pcl::GrabCut< PointT >::initCompute
protected

initGraph()

isSource()

template<typename PointT >
bool pcl::GrabCut< PointT >::isSource ( vertex_descriptor v )
inlineprotected
Returns
true if v is in source tree

Definition at line 446 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::graph_, and pcl::segmentation::grabcut::BoykovKolmogorov::inSourceTree().

refine()

template<typename PointT >
void pcl::GrabCut< PointT >::refine
virtual

Run Grabcut refinement on the hard segmentation.

Definition at line 212 of file grabcut_segmentation.hpp.

refineOnce()

template<typename PointT >
int pcl::GrabCut< PointT >::refineOnce
virtual
Returns
the number of pixels that have changed from foreground to background or vice versa

Definition at line 195 of file grabcut_segmentation.hpp.

References pcl::segmentation::grabcut::learnGMMs().

setBackgroundPoints()

template<typename PointT >
void pcl::GrabCut< PointT >::setBackgroundPoints ( const PointCloudConstPtr & background_points )

Set background points, foreground points = points \ background points.

setBackgroundPointsIndices() [1/2]

template<typename PointT >
void pcl::GrabCut< PointT >::setBackgroundPointsIndices ( const PointIndicesConstPtr & indices )

setBackgroundPointsIndices() [2/2]

template<typename PointT >
void pcl::GrabCut< PointT >::setBackgroundPointsIndices ( int x1,
int y1,
int x2,
int y2
)

Set background indices, foreground indices = indices \ background indices.

setInputCloud()

template<typename PointT >
void pcl::GrabCut< PointT >::setInputCloud ( const PointCloudConstPtr & cloud )
overridevirtual

Provide a pointer to the input dataset.

Parameters
[in] cloud the const boost shared pointer to a PointCloud message

Reimplemented from pcl::PCLBase< PointT >.

Definition at line 81 of file grabcut_segmentation.hpp.

setK()

template<typename PointT >
void pcl::GrabCut< PointT >::setK ( std::uint32_t K )
inline

Set K parameter to user given value.

Suggested value by the authors is 5

Parameters
[in] K the number of components used in GMM

Definition at line 373 of file grabcut_segmentation.h.

References pcl::K, and pcl::GrabCut< PointT >::K_.

setLambda()

template<typename PointT >
void pcl::GrabCut< PointT >::setLambda ( float lambda )
inline

Set lambda parameter to user given value.

Suggested value by the authors is 50

Parameters
[in] lambda

Definition at line 365 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::lambda_.

setNumberOfNeighbours()

template<typename PointT >
void pcl::GrabCut< PointT >::setNumberOfNeighbours ( int nb_neighbours )
inline

Allows to set the number of neighbours to find.

Parameters
[in] nb_neighbours new number of neighbours

Definition at line 386 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::nb_neighbours_.

setSearchMethod()

template<typename PointT >
void pcl::GrabCut< PointT >::setSearchMethod ( const KdTreePtr & tree )
inline

Provide a pointer to the search object.

Parameters
tree a pointer to the spatial search object.

Definition at line 378 of file grabcut_segmentation.h.

References pcl::GrabCut< PointT >::tree_.

setTerminalWeights()

template<typename PointT >
void pcl::GrabCut< PointT >::setTerminalWeights ( vertex_descriptor v,
float source_capacity,
float sink_capacity
)
protected

Set the weights of SOURCE --> v and v --> SINK.

Definition at line 156 of file grabcut_segmentation.hpp.

setTrimap()

updateHardSegmentation()

Member Data Documentation

background_GMM_

template<typename PointT >
segmentation::grabcut::GMM pcl::GrabCut< PointT >::background_GMM_
protected

Definition at line 475 of file grabcut_segmentation.h.

beta_

template<typename PointT >
float pcl::GrabCut< PointT >::beta_
protected

beta = 1/2 * average of the squared color distances between all pairs of 8-neighboring pixels.

Definition at line 457 of file grabcut_segmentation.h.

foreground_GMM_

template<typename PointT >
segmentation::grabcut::GMM pcl::GrabCut< PointT >::foreground_GMM_
protected

Definition at line 475 of file grabcut_segmentation.h.

GMM_component_

template<typename PointT >
std::vector<std::size_t> pcl::GrabCut< PointT >::GMM_component_
protected

Definition at line 471 of file grabcut_segmentation.h.

graph_

template<typename PointT >
pcl::segmentation::grabcut::BoykovKolmogorov pcl::GrabCut< PointT >::graph_
protected

Graph for Graphcut.

Definition at line 478 of file grabcut_segmentation.h.

Referenced by pcl::GrabCut< PointT >::isSource().

graph_nodes_

template<typename PointT >
std::vector<vertex_descriptor> pcl::GrabCut< PointT >::graph_nodes_
protected

Graph nodes.

Definition at line 480 of file grabcut_segmentation.h.

hard_segmentation_

template<typename PointT >
std::vector<segmentation::grabcut::SegmentationValue> pcl::GrabCut< PointT >::hard_segmentation_
protected

Definition at line 472 of file grabcut_segmentation.h.

height_

template<typename PointT >
std::uint32_t pcl::GrabCut< PointT >::height_
protected

image height

Definition at line 450 of file grabcut_segmentation.h.

image_

template<typename PointT >
segmentation::grabcut::Image::Ptr pcl::GrabCut< PointT >::image_
protected

Converted input.

Definition at line 469 of file grabcut_segmentation.h.

initialized_

template<typename PointT >
bool pcl::GrabCut< PointT >::initialized_
protected

is segmentation initialized

Definition at line 465 of file grabcut_segmentation.h.

K_

template<typename PointT >
std::uint32_t pcl::GrabCut< PointT >::K_
protected

Number of GMM components.

Definition at line 453 of file grabcut_segmentation.h.

Referenced by pcl::GrabCut< PointT >::getK(), and pcl::GrabCut< PointT >::setK().

L_

template<typename PointT >
float pcl::GrabCut< PointT >::L_
protected

L = a large value to force a pixel to be foreground or background.

Definition at line 459 of file grabcut_segmentation.h.

lambda_

template<typename PointT >
float pcl::GrabCut< PointT >::lambda_
protected

lambda = 50. This value was suggested the GrabCut paper.

Definition at line 455 of file grabcut_segmentation.h.

Referenced by pcl::GrabCut< PointT >::getLambda(), and pcl::GrabCut< PointT >::setLambda().

n_links_

template<typename PointT >
std::vector<NLinks> pcl::GrabCut< PointT >::n_links_
protected

Precomputed N-link weights.

Definition at line 467 of file grabcut_segmentation.h.

nb_neighbours_

template<typename PointT >
int pcl::GrabCut< PointT >::nb_neighbours_
protected

soft_segmentation_

template<typename PointT >
std::vector<float> pcl::GrabCut< PointT >::soft_segmentation_
protected

Definition at line 474 of file grabcut_segmentation.h.

tree_

template<typename PointT >
KdTreePtr pcl::GrabCut< PointT >::tree_
protected

Pointer to the spatial search object.

Definition at line 461 of file grabcut_segmentation.h.

Referenced by pcl::GrabCut< PointT >::getSearchMethod(), and pcl::GrabCut< PointT >::setSearchMethod().

trimap_

template<typename PointT >
std::vector<segmentation::grabcut::TrimapValue> pcl::GrabCut< PointT >::trimap_
protected

Definition at line 470 of file grabcut_segmentation.h.

width_

template<typename PointT >
std::uint32_t pcl::GrabCut< PointT >::width_
protected

image width

Definition at line 448 of file grabcut_segmentation.h.


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

© 2009–2012, Willow Garage, Inc.
© 2012–, Open Perception, Inc.
Licensed under the BSD License.
https://pointclouds.org/documentation/classpcl_1_1_grab_cut.html