Point Cloud Library (PCL)
1.11.1-dev
|
45 #include <pcl/point_cloud.h>
46 #include <pcl/pcl_base.h>
49 #include <pcl/search/search.h>
53 namespace segmentation
84 addNodes (std::size_t n = 1);
90 addSourceEdge (
int u,
double cap);
93 addTargetEdge (
int u,
double cap);
97 addEdge (
int u,
int v,
double cap_uv,
double cap_vu = 0.0);
109 operator() (
int u,
int v)
const;
112 getSourceEdgeCapacity (
int u)
const;
115 getTargetEdgeCapacity (
int u)
const;
119 enum nodestate { FREE = 0x00, SOURCE = 0x01, TARGET = 0x02 };
123 using edge_pair = std::pair<capacitated_edge::iterator, capacitated_edge::iterator>;
135 augmentPath (
const std::pair<int, int>& path, std::deque<int>& orphans);
138 adoptOrphans (std::deque<int>& orphans);
146 isActive (
int u)
const {
return ((u == active_head_) || (active_list_[u].first != TERMINAL)); }
152 markInactive (
int u);
162 std::vector<unsigned char>
cut_;
166 static const int TERMINAL;
168 std::vector<std::pair<int, edge_pair> > parents_;
170 std::vector<std::pair<int, int> > active_list_;
171 int active_head_, active_tail_;
178 Color (
float _r,
float _g,
float _b) :
r(_r),
g(_g),
b(_b) {}
181 template<
typename Po
intT>
184 template<
typename Po
intT>
226 GMM () : gaussians_ (0) {}
228 GMM (std::size_t
K) : gaussians_ (
K) {}
233 getK ()
const {
return gaussians_.size (); }
239 operator[] (std::size_t pos) {
return (gaussians_[pos]); }
242 operator[] (std::size_t pos)
const {
return (gaussians_[pos]); }
245 probabilityDensity (
const Color &c);
248 probabilityDensity(std::size_t i,
const Color &c);
252 std::vector<Gaussian> gaussians_;
260 : sum_ (
Eigen::Vector3f::Zero ())
261 , accumulator_ (
Eigen::Matrix3f::Zero ())
271 fit (
Gaussian& g, std::size_t total_count,
bool compute_eigens =
false)
const;
284 Eigen::Vector3f sum_;
286 Eigen::Matrix3f accumulator_;
288 std::uint32_t count_;
298 const std::vector<SegmentationValue> &hardSegmentation,
299 std::vector<std::size_t> &components,
300 GMM &background_GMM, GMM &foreground_GMM);
305 const std::vector<SegmentationValue>& hard_segmentation,
306 std::vector<std::size_t>& components,
307 GMM& background_GMM, GMM& foreground_GMM);
319 template <
typename Po
intT>
396 extract (std::vector<pcl::PointIndices>& clusters);
470 std::vector<segmentation::grabcut::TrimapValue>
trimap_;
484 #include <pcl/segmentation/impl/grabcut_segmentation.hpp>
Defines all the PCL and non-PCL macros used.
void fit(Gaussian &g, std::size_t total_count, bool compute_eigens=false) const
Build the gaussian out of all the added color samples.
segmentation::grabcut::Image::Ptr image_
Converted input.
void computeBetaOrganized()
Compute beta from image.
KdTreePtr getSearchMethod()
Get a pointer to the search method used.
typename PointCloud::ConstPtr PointCloudConstPtr
std::vector< double > source_edges_
edges leaving the source
typename PointCloud::Ptr PointCloudPtr
PCL_EXPORTS void learnGMMs(const Image &image, const Indices &indices, const std::vector< SegmentationValue > &hard_segmentation, std::vector< std::size_t > &components, GMM &background_GMM, GMM &foreground_GMM)
Iteratively learn GMMs using GrabCut updating algorithm.
std::vector< segmentation::grabcut::TrimapValue > trimap_
virtual ~BoykovKolmogorov()
destructor
Helper class that fits a single Gaussian to color samples.
float determinant
determinant of the covariance matrix
GMM()
Initialize GMM with ddesired number of gaussians.
Implementation of the GrabCut segmentation in "GrabCut — Interactive Foreground Extraction using Iter...
void setEpsilon(float epsilon)
set epsilon which will be added to the covariance matrix diagonal which avoids singular covariance ma...
std::size_t numNodes() const
get number of nodes in the graph
void setInputCloud(const PointCloudConstPtr &cloud) override
Provide a pointer to the input dataset.
PointIndices::ConstPtr PointIndicesConstPtr
void computeL()
Compute L parameter from given lambda.
PointCloud represents the base class in PCL for storing collections of 3D points.
GaussianFitter(float epsilon=0.0001)
segmentation::grabcut::GMM foreground_GMM_
A point structure representing Euclidean xyz coordinates, and the RGB color.
virtual void refine()
Run Grabcut refinement on the hard segmentation.
pcl::segmentation::grabcut::BoykovKolmogorov graph_
Graph for Graphcut.
segmentation::grabcut::GMM background_GMM_
GrabCut(std::uint32_t K=5, float lambda=50.f)
Constructor.
void setTerminalWeights(vertex_descriptor v, float source_capacity, float sink_capacity)
Set the weights of SOURCE --> v and v --> SINK.
std::vector< float > weights
Eigen::Vector3f eigenvector
eigenvector corresponding to the highest eigenvector
void setK(std::uint32_t K)
Set K parameter to user given value.
std::vector< segmentation::grabcut::SegmentationValue > hard_segmentation_
double flow_value_
current flow value (includes constant)
PCL_EXPORTS void buildGMMs(const Image &image, const Indices &indices, const std::vector< SegmentationValue > &hardSegmentation, std::vector< std::size_t > &components, GMM &background_GMM, GMM &foreground_GMM)
Build the initial GMMs using the Orchard and Bouman color clustering algorithm.
bool isSource(vertex_descriptor v)
PointIndices::ConstPtr PointIndicesConstPtr
int updateHardSegmentation()
float colorDistance(const Color &c1, const Color &c2)
Compute squared distance between two colors.
SegmentationValue
Grabcut derived hard segmentation values.
Eigen::Matrix3f covariance
covariance matrix of the gaussian
std::vector< unsigned char > cut_
identifies which side of the cut a node falls
virtual void fitGMMs()
Fit Gaussian Multi Models.
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
bool initialized_
is segmentation initialized
void computeNLinksNonOrganized()
Compute NLinks from cloud.
std::uint32_t width_
image width
TrimapValue
User supplied Trimap values.
void setBackgroundPointsIndices(int x1, int y1, int x2, int y2)
Set background indices, foreground indices = indices \ background indices.
int nb_neighbours_
Number of neighbours.
shared_ptr< pcl::search::Search< PointT > > Ptr
float beta_
beta = 1/2 * average of the squared color distances between all pairs of 8-neighboring pixels.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
pcl::segmentation::grabcut::BoykovKolmogorov::vertex_descriptor vertex_descriptor
A structure representing RGB color information.
void addConstant(double c)
add constant flow to graph
std::vector< std::size_t > GMM_component_
float L_
L = a large value to force a pixel to be foreground or background.
void add(const Color &c)
Add a color sample.
Eigen::Matrix3f inverse
inverse of the covariance matrix
Color(const pcl::RGB &color)
std::pair< capacitated_edge::iterator, capacitated_edge::iterator > edge_pair
edge pair
void setLambda(float lambda)
Set lambda parameter to user given value.
void computeNLinksOrganized()
Compute NLinks from image.
IndicesAllocator<> Indices
Type used for indices in PCL.
void resize(std::size_t K)
resize gaussians
float eigenvalue
highest eigenvalue of covariance matrix
std::uint32_t height_
image height
void setTrimap(const PointIndicesConstPtr &indices, segmentation::grabcut::TrimapValue t)
Edit Trimap.
void initGraph()
Build the graph for GraphCut.
shared_ptr< PointCloud< PointT > > Ptr
int getNumberOfNeighbours() const
Returns the number of neighbours to find.
std::vector< float > soft_segmentation_
std::map< int, double > capacitated_edge
capacitated edge
float pi
weighting of this gaussian in the GMM.
std::uint32_t K_
Number of GMM components.
std::vector< float > dists
typename KdTree::Ptr KdTreePtr
double edge_capacity_type
bool isActive(int u) const
active if head or previous node is not the terminal
GMM(std::size_t K)
Initialize GMM with ddesired number of gaussians.
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.
bool isActiveSetEmpty() const
bool inSinkTree(int u) const
return true if u is in the t-set after calling solve
void computeBetaNonOrganized()
Compute beta from cloud.
Structure to save RGB colors into floats.
void extract(std::vector< pcl::PointIndices > &clusters)
This method launches the segmentation algorithm and returns the clusters that were obtained during th...
Color(float _r, float _g, float _b)
std::vector< vertex_descriptor > graph_nodes_
Graph nodes.
void setNumberOfNeighbours(int nb_neighbours)
Allows to set the number of neighbours to find.
boost implementation of Boykov and Kolmogorov's maxflow algorithm doesn't support negative flows whic...
pcl::PointCloud< Color > Image
An Image is a point cloud of Color.
KdTreePtr tree_
Pointer to the spatial search object.
float lambda_
lambda = 50. This value was suggested the GrabCut paper.
Defines functions, macros and traits for allocating and using memory.
std::vector< NLinks > n_links_
Precomputed N-link weights.
std::vector< capacitated_edge > nodes_
nodes and their outgoing internal edges
void setBackgroundPoints(const PointCloudConstPtr &background_points)
Set background points, foreground points = points \ background points.
Color mu
mean of the gaussian
bool inSourceTree(int u) const
return true if u is in the s-set after calling solve.
std::vector< double > target_edges_
edges entering the target