473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help with initialization of graph (Boost Graph Library)

I'm trying to create a graph from an image, where pixel values are
regions labels. I have defined my graph to use lists instead of the
vectors (because I need to add/remove vertices and edges) and one extra
property for the vertex (the region label):

typedef boost::adjacency_list<
boost::listS, // Adjacency list
boost::listS, // Vertex list
boost::undirectedS, // Undirected graph
unsigned int, // Vertex property (=label)
boost::no_property, // Edge property
boost::no_property, // Graph property
boost::listS // Edge list
graph;

typedef boost::graph_traits<graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<graph>::edge_descriptor edge_t;

I have the following pseudo code to populate the graph:

graph g;
for each pixel (i,j) {
unsigned int u_label = image[i][j];
for each neighbourhood pixel (k,l) {
unsigned int v_label = image[k][l];
if (u_label != v_label) {
// Find/add both vertices
vertex_t u = boost::add_vertex(u_label,g);
vertex_t v = boost::add_vertex(v_label, g);
// Find/add edge
boost::add_edge(u, v, g);
}
}
}

But this creates many duplicates (with regard to the label) for both
vertices and edges. How can i prevent this? Would using a set for the
edges solves my problem? And how can I add a vertex only if it does not
exist already?
Jan 23 '06 #1
3 7801
Jef Driesen wrote:
I'm trying to create a graph from an image, where pixel values are
regions labels. I have defined my graph to use lists instead of the
vectors (because I need to add/remove vertices and edges) and one extra
property for the vertex (the region label):

typedef boost::adjacency_list<
boost::listS, // Adjacency list
boost::listS, // Vertex list
boost::undirectedS, // Undirected graph
unsigned int, // Vertex property (=label)
boost::no_property, // Edge property
boost::no_property, // Graph property
boost::listS // Edge list
> graph;

typedef boost::graph_traits<graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<graph>::edge_descriptor edge_t;

I have the following pseudo code to populate the graph:

graph g;
for each pixel (i,j) {
unsigned int u_label = image[i][j];
for each neighbourhood pixel (k,l) {
unsigned int v_label = image[k][l];
if (u_label != v_label) {
// Find/add both vertices
vertex_t u = boost::add_vertex(u_label,g);
vertex_t v = boost::add_vertex(v_label, g);
// Find/add edge
boost::add_edge(u, v, g);
}
}
}

But this creates many duplicates (with regard to the label) for both
vertices and edges. How can i prevent this? Would using a set for the
edges solves my problem? And how can I add a vertex only if it does not
exist already?


This post is off-topic here (see FAQ 5.9). You probably want to post to
the Boost users list:

http://boost.org/more/mailing_lists.htm#users

Cheers! --M

Jan 23 '06 #2
mlimber wrote:
Jef Driesen wrote:
I'm trying to create a graph from an image, where pixel values are
regions labels. I have defined my graph to use lists instead of the
vectors (because I need to add/remove vertices and edges) and one extra
property for the vertex (the region label):

typedef boost::adjacency_list<
boost::listS, // Adjacency list
boost::listS, // Vertex list
boost::undirectedS, // Undirected graph
unsigned int, // Vertex property (=label)
boost::no_property, // Edge property
boost::no_property, // Graph property
boost::listS // Edge list
> graph;

typedef boost::graph_traits<graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<graph>::edge_descriptor edge_t;

I have the following pseudo code to populate the graph:

graph g;
for each pixel (i,j) {
unsigned int u_label = image[i][j];
for each neighbourhood pixel (k,l) {
unsigned int v_label = image[k][l];
if (u_label != v_label) {
// Find/add both vertices
vertex_t u = boost::add_vertex(u_label,g);
vertex_t v = boost::add_vertex(v_label, g);
// Find/add edge
boost::add_edge(u, v, g);
}
}
}

But this creates many duplicates (with regard to the label) for both
vertices and edges. How can i prevent this? Would using a set for the
edges solves my problem? And how can I add a vertex only if it does not
exist already?


This post is off-topic here (see FAQ 5.9). You probably want to post to
the Boost users list:

http://boost.org/more/mailing_lists.htm#users


I do not entirely agree with you that my post is off-topic here, but
it's a good idea do post my question to the boost users list anyway. I
wasn't even aware of the existence of that list.
Jan 24 '06 #3
Jef Driesen wrote:
mlimber wrote:
This post is off-topic here (see FAQ 5.9). You probably want to post to
the Boost users list:

http://boost.org/more/mailing_lists.htm#users


I do not entirely agree with you that my post is off-topic here, but
it's a good idea do post my question to the boost users list anyway. I
wasn't even aware of the existence of that list.


I suppose the original post could be in the gray area for this
newsgroup, but since the graph library is not part of TR1, you'll
likely get better help from the Boost user's list.

Cheers! --M

Jan 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Magnus Lie Hetland | last post by:
Is there any interest in a (hypothetical) standard graph API (with 'graph' meaning a network, consisting of nodes and edges)? Yes, we have the standard ways of implementing graphs through (e.g.)...
7
by: Dax | last post by:
Hi, I'm using boost library, I want to create a graph of a library in c++, and, for example, every leave is a book, inside it there are some variables, like title, if is available, description,...
8
by: Daniele | last post by:
Hi there is a way to put in a struct of vectors all the possibles routes in a graph from s to d? Hi thought Dijkstra but I don't know how can i do. Thanks Dax
2
by: Christian Christmann | last post by:
Hi, I need to write a graph which provides at least the following functions: 1) stores nodes and edges (both store further information which can be of any type) 2) manipulations on nodes and...
8
by: Jef Driesen | last post by:
I'm working on an image segmentation algorithm. An essential part of the algorithm is a graph to keep track of the connectivity between regions. At the moment I have a working implementation, but...
3
by: Amol | last post by:
I am working on an interesting graph optimization problem and I would like to have a few expert opinions for helping me with a solution. So here goes ... I have a black box with a complex...
10
by: diffuser78 | last post by:
Is there any library in Python which has implementation of graph theoretic algorithms and models ?
0
by: Tim Frink | last post by:
Hi, I want to use the depth_first_search algorithm from the Boost Graph Library. However, I've problems with the definition of my own ColorMap. To illustrate this, here is an example (taken...
1
by: rboorgapally | last post by:
Hi everyone, I am trying to run BFS on a graph that is created with input from a file. I am facing problems with the output though the code is compiling: #include <boost/graph/adjacency_list.hpp>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.