我正在尝试使用实现"智能剪刀"进行交互式图像分割.因此,我必须从图像创建有向图,其中每个顶点表示单个像素.然后通过两个边缘将每个顶点连接到其每个邻居:一个输出边缘和一个输入边缘.这是因为边缘(a,b)的成本可能与(b,a)的成本不同.我正在使用尺寸为512*512像素的图像,因此我需要创建一个包含262144个顶点和2091012个边的图形.目前,我正在使用以下图表:
typedef property<vertex_index_t, int,
property<vertex_distance_t, double,
property<x_t, int,
property<y_t, int
>>>> VertexProperty;
typedef property<edge_weight_t, double> EdgeProperty;
// define MyGraph
typedef adjacency_list<
vecS, // container used for the out-edges (list)
vecS, // container used for the vertices (vector)
directedS, // directed edges (not sure if this is the right choice for incidenceGraph)
VertexProperty,
EdgeProperty
> MyGraph;
Run Code Online (Sandbox Code Playgroud)
我正在使用一个额外的类Graph(抱歉没有灵感的命名)来处理图形:
class Graph
{
private:
MyGraph *graph;
property_map<MyGraph, vertex_index_t>::type indexmap;
property_map<MyGraph, vertex_distance_t>::type distancemap;
property_map<MyGraph, edge_weight_t>::type weightmap;
property_map<MyGraph, x_t>::type xmap;
property_map<MyGraph, y_t>::type ymap;
std::vector<MyGraph::vertex_descriptor> …Run Code Online (Sandbox Code Playgroud)