|
Point Cloud Library (PCL) 1.15.0
|
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. | |
| ~GrabCut () override=default | |
| Destructor. | |
| void | setInputCloud (const PointCloudConstPtr &cloud) override |
| Provide a pointer to the input dataset. | |
| void | setBackgroundPoints (const PointCloudConstPtr &background_points) |
| Set background points, foreground points = points \ background points. | |
| void | setBackgroundPointsIndices (int x1, int y1, int x2, int y2) |
| Set background indices, foreground indices = indices \ background indices. | |
| void | setBackgroundPointsIndices (const PointIndicesConstPtr &indices) |
| Set background indices, foreground indices = indices \ background indices. | |
| virtual void | refine () |
| Run Grabcut refinement on the hard segmentation. | |
| virtual int | refineOnce () |
| float | getLambda () |
| void | setLambda (float lambda) |
| Set lambda parameter to user given value. | |
| std::uint32_t | getK () |
| void | setK (std::uint32_t K) |
| Set K parameter to user given value. | |
| void | setSearchMethod (const KdTreePtr &tree) |
| Provide a pointer to the search object. | |
| KdTreePtr | getSearchMethod () |
| Get a pointer to the search method used. | |
| void | setNumberOfNeighbours (int nb_neighbours) |
| Allows to set the number of neighbours to find. | |
| int | getNumberOfNeighbours () const |
| Returns the number of neighbours to find. | |
| void | extract (std::vector< pcl::PointIndices > &clusters) |
| This method launches the segmentation algorithm and returns the clusters that were obtained during the segmentation. | |
| Public Member Functions inherited from pcl::PCLBase< PointT > | |
| PCLBase () | |
| Empty constructor. | |
| PCLBase (const PCLBase &base) | |
| Copy constructor. | |
| virtual | ~PCLBase ()=default |
| Destructor. | |
| PointCloudConstPtr const | getInputCloud () const |
| Get a pointer to the input point cloud dataset. | |
| virtual void | setIndices (const IndicesPtr &indices) |
| Provide a pointer to the vector of indices that represents the input data. | |
| virtual void | setIndices (const IndicesConstPtr &indices) |
| Provide a pointer to the vector of indices that represents the input data. | |
| virtual void | setIndices (const PointIndicesConstPtr &indices) |
| Provide a pointer to the vector of indices that represents the input data. | |
| 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. | |
| IndicesPtr | getIndices () |
| Get a pointer to the vector of indices used. | |
| IndicesConstPtr const | getIndices () const |
| Get a pointer to the vector of indices used. | |
| const PointT & | operator[] (std::size_t pos) const |
| Override PointCloud operator[] to shorten code. | |
Protected Types | |
| using | vertex_descriptor = pcl::segmentation::grabcut::BoykovKolmogorov::vertex_descriptor |
Protected Member Functions | |
| bool | initCompute () |
| void | computeBetaOrganized () |
| Compute beta from image. | |
| void | computeBetaNonOrganized () |
| Compute beta from cloud. | |
| void | computeL () |
| Compute L parameter from given lambda. | |
| void | computeNLinksOrganized () |
| Compute NLinks from image. | |
| void | computeNLinksNonOrganized () |
| Compute NLinks from cloud. | |
| void | setTrimap (const PointIndicesConstPtr &indices, segmentation::grabcut::TrimapValue t) |
| Edit Trimap. | |
| int | updateHardSegmentation () |
| virtual void | fitGMMs () |
| Fit Gaussian Multi Models. | |
| void | initGraph () |
| Build the graph for GraphCut. | |
| 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. | |
| void | setTerminalWeights (vertex_descriptor v, float source_capacity, float sink_capacity) |
| Set the weights of SOURCE --> v and v --> SINK. | |
| 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. | |
| bool | deinitCompute () |
| This method should get called after finishing the actual computation. | |
Protected Attributes | |
| std::uint32_t | width_ {0} |
| image width | |
| std::uint32_t | height_ {0} |
| image height | |
| std::uint32_t | K_ |
| Number of GMM components. | |
| float | lambda_ |
| lambda = 50. This value was suggested the GrabCut paper. | |
| float | beta_ {0.0f} |
| beta = 1/2 * average of the squared color distances between all pairs of 8-neighboring pixels. | |
| float | L_ {0.0f} |
| L = a large value to force a pixel to be foreground or background. | |
| KdTreePtr | tree_ {nullptr} |
| Pointer to the spatial search object. | |
| int | nb_neighbours_ {9} |
| Number of neighbours. | |
| bool | initialized_ {false} |
| is segmentation initialized | |
| std::vector< NLinks > | n_links_ {} |
| Precomputed N-link weights. | |
| segmentation::grabcut::Image::Ptr | image_ |
| Converted input. | |
| 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. | |
| std::vector< vertex_descriptor > | graph_nodes_ {} |
| Graph nodes. | |
| Protected Attributes inherited from pcl::PCLBase< PointT > | |
| PointCloudConstPtr | input_ |
| The input point cloud dataset. | |
| IndicesPtr | indices_ |
| A pointer to the vector of point indices to use. | |
| bool | use_indices_ |
| Set to true if point indices are used. | |
| bool | fake_indices_ |
| If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. | |
Implementation of the GrabCut segmentation in "GrabCut — Interactive Foreground Extraction using Iterated Graph Cuts" by Carsten Rother, Vladimir Kolmogorov and Andrew Blake.
Definition at line 317 of file grabcut_segmentation.h.
| using pcl::GrabCut< PointT >::KdTree = pcl::search::Search<PointT> |
Definition at line 320 of file grabcut_segmentation.h.
| using pcl::GrabCut< PointT >::KdTreePtr = typename KdTree::Ptr |
Definition at line 321 of file grabcut_segmentation.h.
| using pcl::GrabCut< PointT >::PointCloudConstPtr = typename PCLBase<PointT>::PointCloudConstPtr |
Definition at line 322 of file grabcut_segmentation.h.
| using pcl::GrabCut< PointT >::PointCloudPtr = typename PCLBase<PointT>::PointCloudPtr |
Definition at line 323 of file grabcut_segmentation.h.
|
protected |
Definition at line 404 of file grabcut_segmentation.h.
|
inline |
Constructor.
Definition at line 329 of file grabcut_segmentation.h.
|
overridedefault |
Destructor.
|
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.
References graph_.
Referenced by initGraph().
|
protected |
Compute beta from cloud.
Definition at line 387 of file grabcut_segmentation.hpp.
References beta_, pcl::GrabCut< PointT >::NLinks::dists, image_, pcl::GrabCut< PointT >::NLinks::indices, pcl::PCLBase< PointT >::indices_, pcl::PCLBase< PointT >::input_, pcl::isFinite(), n_links_, pcl::GrabCut< PointT >::NLinks::nb_links, nb_neighbours_, pcl::squaredEuclideanDistance(), tree_, and pcl::GrabCut< PointT >::NLinks::weights.
Referenced by initCompute().
|
protected |
Compute beta from image.
Definition at line 426 of file grabcut_segmentation.hpp.
References beta_, pcl::GrabCut< PointT >::NLinks::dists, image_, pcl::GrabCut< PointT >::NLinks::indices, pcl::PCLBase< PointT >::input_, n_links_, pcl::GrabCut< PointT >::NLinks::nb_links, pcl::squaredEuclideanDistance(), and pcl::GrabCut< PointT >::NLinks::weights.
Referenced by initCompute().
|
protected |
Compute L parameter from given lambda.
Definition at line 496 of file grabcut_segmentation.hpp.
Referenced by initCompute().
|
protected |
Compute NLinks from cloud.
Definition at line 334 of file grabcut_segmentation.hpp.
References beta_, pcl::GrabCut< PointT >::NLinks::dists, pcl::GrabCut< PointT >::NLinks::indices, pcl::PCLBase< PointT >::indices_, lambda_, n_links_, pcl::GrabCut< PointT >::NLinks::nb_links, and pcl::GrabCut< PointT >::NLinks::weights.
Referenced by initCompute().
|
protected |
Compute NLinks from image.
Definition at line 360 of file grabcut_segmentation.hpp.
References beta_, pcl::GrabCut< PointT >::NLinks::dists, image_, pcl::PCLBase< PointT >::input_, lambda_, n_links_, and pcl::GrabCut< PointT >::NLinks::weights.
Referenced by initCompute().
| 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.
| [out] | clusters | clusters that were obtained. Each cluster is an array of point indices. |
Definition at line 502 of file grabcut_segmentation.hpp.
References hard_segmentation_, pcl::PCLBase< PointT >::indices_, refine(), and pcl::segmentation::grabcut::SegmentationForeground.
|
protectedvirtual |
Fit Gaussian Multi Models.
Definition at line 185 of file grabcut_segmentation.hpp.
References background_GMM_, pcl::segmentation::grabcut::buildGMMs(), foreground_GMM_, GMM_component_, hard_segmentation_, image_, pcl::PCLBase< PointT >::indices_, and initGraph().
Referenced by setBackgroundPointsIndices().
|
inline |
Definition at line 361 of file grabcut_segmentation.h.
References K_.
|
inline |
|
inline |
Returns the number of neighbours to find.
Definition at line 382 of file grabcut_segmentation.h.
References nb_neighbours_.
|
inline |
Get a pointer to the search method used.
Definition at line 374 of file grabcut_segmentation.h.
References tree_.
|
protected |
Definition at line 87 of file grabcut_segmentation.hpp.
References background_GMM_, computeBetaNonOrganized(), computeBetaOrganized(), computeL(), computeNLinksNonOrganized(), computeNLinksOrganized(), foreground_GMM_, pcl::getFieldIndex(), GMM_component_, hard_segmentation_, height_, image_, pcl::PCLBase< PointT >::indices_, pcl::PCLBase< PointT >::initCompute(), initialized_, pcl::PCLBase< PointT >::input_, K_, n_links_, pcl::segmentation::grabcut::SegmentationBackground, tree_, trimap_, pcl::segmentation::grabcut::TrimapUnknown, and width_.
Referenced by setBackgroundPointsIndices().
|
protected |
Build the graph for GraphCut.
Definition at line 269 of file grabcut_segmentation.hpp.
References addEdge(), background_GMM_, foreground_GMM_, graph_, graph_nodes_, image_, pcl::GrabCut< PointT >::NLinks::indices, pcl::PCLBase< PointT >::indices_, L_, n_links_, pcl::GrabCut< PointT >::NLinks::nb_links, setTerminalWeights(), trimap_, pcl::segmentation::grabcut::TrimapBackground, pcl::segmentation::grabcut::TrimapUnknown, pcl::UNAVAILABLE, and pcl::GrabCut< PointT >::NLinks::weights.
Referenced by fitGMMs(), and refineOnce().
|
inlineprotected |
Definition at line 439 of file grabcut_segmentation.h.
References graph_.
Referenced by updateHardSegmentation().
|
virtual |
Run Grabcut refinement on the hard segmentation.
Definition at line 212 of file grabcut_segmentation.hpp.
References pcl::PCLBase< PointT >::indices_, and refineOnce().
Referenced by extract().
|
virtual |
Definition at line 195 of file grabcut_segmentation.hpp.
References background_GMM_, foreground_GMM_, GMM_component_, graph_, hard_segmentation_, image_, pcl::PCLBase< PointT >::indices_, initGraph(), pcl::segmentation::grabcut::learnGMMs(), and updateHardSegmentation().
Referenced by refine().
| void pcl::GrabCut< PointT >::setBackgroundPoints | ( | const PointCloudConstPtr & | background_points | ) |
Set background points, foreground points = points \ background points.
| void pcl::GrabCut< PointT >::setBackgroundPointsIndices | ( | const PointIndicesConstPtr & | indices | ) |
Set background indices, foreground indices = indices \ background indices.
Definition at line 163 of file grabcut_segmentation.hpp.
References fitGMMs(), hard_segmentation_, initCompute(), initialized_, pcl::segmentation::grabcut::SegmentationBackground, pcl::segmentation::grabcut::SegmentationForeground, trimap_, pcl::segmentation::grabcut::TrimapBackground, and pcl::segmentation::grabcut::TrimapUnknown.
| void pcl::GrabCut< PointT >::setBackgroundPointsIndices | ( | int | x1, |
| int | y1, | ||
| int | x2, | ||
| int | y2 ) |
Set background indices, foreground indices = indices \ background indices.
|
overridevirtual |
Provide a pointer to the input dataset.
| [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.
References pcl::PCLBase< PointT >::input_.
|
inline |
Set K parameter to user given value.
Suggested value by the authors is 5
| [in] | K | the number of components used in GMM |
Definition at line 366 of file grabcut_segmentation.h.
|
inline |
Set lambda parameter to user given value.
Suggested value by the authors is 50
| [in] | lambda |
Definition at line 358 of file grabcut_segmentation.h.
References lambda_.
|
inline |
Allows to set the number of neighbours to find.
| [in] | nb_neighbours | new number of neighbours |
Definition at line 379 of file grabcut_segmentation.h.
References nb_neighbours_.
|
inline |
Provide a pointer to the search object.
| tree | a pointer to the spatial search object. |
Definition at line 371 of file grabcut_segmentation.h.
References tree_.
|
protected |
Set the weights of SOURCE --> v and v --> SINK.
Definition at line 156 of file grabcut_segmentation.hpp.
References graph_.
Referenced by initGraph().
|
protected |
Edit Trimap.
Definition at line 252 of file grabcut_segmentation.hpp.
References hard_segmentation_, pcl::segmentation::grabcut::SegmentationBackground, pcl::segmentation::grabcut::SegmentationForeground, trimap_, pcl::segmentation::grabcut::TrimapBackground, and pcl::segmentation::grabcut::TrimapForeground.
|
protected |
Definition at line 221 of file grabcut_segmentation.hpp.
References graph_nodes_, hard_segmentation_, pcl::PCLBase< PointT >::indices_, isSource(), pcl::segmentation::grabcut::SegmentationBackground, pcl::segmentation::grabcut::SegmentationForeground, trimap_, pcl::segmentation::grabcut::TrimapBackground, and pcl::segmentation::grabcut::TrimapForeground.
Referenced by refineOnce().
|
protected |
Definition at line 468 of file grabcut_segmentation.h.
Referenced by fitGMMs(), initCompute(), initGraph(), and refineOnce().
|
protected |
beta = 1/2 * average of the squared color distances between all pairs of 8-neighboring pixels.
Definition at line 450 of file grabcut_segmentation.h.
Referenced by computeBetaNonOrganized(), computeBetaOrganized(), computeNLinksNonOrganized(), and computeNLinksOrganized().
|
protected |
Definition at line 468 of file grabcut_segmentation.h.
Referenced by fitGMMs(), initCompute(), initGraph(), and refineOnce().
|
protected |
Definition at line 464 of file grabcut_segmentation.h.
Referenced by fitGMMs(), initCompute(), and refineOnce().
|
protected |
Graph for Graphcut.
Definition at line 471 of file grabcut_segmentation.h.
Referenced by addEdge(), initGraph(), isSource(), refineOnce(), and setTerminalWeights().
|
protected |
Graph nodes.
Definition at line 473 of file grabcut_segmentation.h.
Referenced by initGraph(), and updateHardSegmentation().
|
protected |
Definition at line 465 of file grabcut_segmentation.h.
Referenced by extract(), fitGMMs(), initCompute(), refineOnce(), setBackgroundPointsIndices(), setTrimap(), and updateHardSegmentation().
|
protected |
|
protected |
Converted input.
Definition at line 462 of file grabcut_segmentation.h.
Referenced by computeBetaNonOrganized(), computeBetaOrganized(), computeNLinksOrganized(), fitGMMs(), initCompute(), initGraph(), and refineOnce().
|
protected |
is segmentation initialized
Definition at line 458 of file grabcut_segmentation.h.
Referenced by initCompute(), and setBackgroundPointsIndices().
|
protected |
Number of GMM components.
Definition at line 446 of file grabcut_segmentation.h.
Referenced by getK(), GrabCut(), initCompute(), and setK().
|
protected |
L = a large value to force a pixel to be foreground or background.
Definition at line 452 of file grabcut_segmentation.h.
Referenced by computeL(), and initGraph().
|
protected |
lambda = 50. This value was suggested the GrabCut paper.
Definition at line 448 of file grabcut_segmentation.h.
Referenced by computeL(), computeNLinksNonOrganized(), computeNLinksOrganized(), getLambda(), GrabCut(), and setLambda().
|
protected |
Precomputed N-link weights.
Definition at line 460 of file grabcut_segmentation.h.
Referenced by computeBetaNonOrganized(), computeBetaOrganized(), computeNLinksNonOrganized(), computeNLinksOrganized(), initCompute(), and initGraph().
|
protected |
Number of neighbours.
Definition at line 456 of file grabcut_segmentation.h.
Referenced by computeBetaNonOrganized(), getNumberOfNeighbours(), and setNumberOfNeighbours().
|
protected |
Definition at line 467 of file grabcut_segmentation.h.
|
protected |
Pointer to the spatial search object.
Definition at line 454 of file grabcut_segmentation.h.
Referenced by computeBetaNonOrganized(), getSearchMethod(), initCompute(), and setSearchMethod().
|
protected |
Definition at line 463 of file grabcut_segmentation.h.
Referenced by initCompute(), initGraph(), setBackgroundPointsIndices(), setTrimap(), and updateHardSegmentation().
|
protected |