473,748 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::adjacenc y_list<
boost::listS, // Adjacency list
boost::listS, // Vertex list
boost::undirect edS, // Undirected graph
unsigned int, // Vertex property (=label)
boost::no_prope rty, // Edge property
boost::no_prope rty, // Graph property
boost::listS // Edge list
graph;

typedef boost::graph_tr aits<graph>::ve rtex_descriptor vertex_t;
typedef boost::graph_tr aits<graph>::ed ge_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_vert ex(u_label,g);
vertex_t v = boost::add_vert ex(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 7831
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::adjacenc y_list<
boost::listS, // Adjacency list
boost::listS, // Vertex list
boost::undirect edS, // Undirected graph
unsigned int, // Vertex property (=label)
boost::no_prope rty, // Edge property
boost::no_prope rty, // Graph property
boost::listS // Edge list
> graph;

typedef boost::graph_tr aits<graph>::ve rtex_descriptor vertex_t;
typedef boost::graph_tr aits<graph>::ed ge_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_vert ex(u_label,g);
vertex_t v = boost::add_vert ex(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::adjacenc y_list<
boost::listS, // Adjacency list
boost::listS, // Vertex list
boost::undirect edS, // Undirected graph
unsigned int, // Vertex property (=label)
boost::no_prope rty, // Edge property
boost::no_prope rty, // Graph property
boost::listS // Edge list
> graph;

typedef boost::graph_tr aits<graph>::ve rtex_descriptor vertex_t;
typedef boost::graph_tr aits<graph>::ed ge_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_vert ex(u_label,g);
vertex_t v = boost::add_vert ex(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
3792
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.) dicts mapping nodes to neighbor-sets, but if one wants a graph that's implemented in some other way, this may not be the most convenient (or abstract) interface to emulate. It might be nice to have the kind of polymorphic freedom that one has with,...
7
1690
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, number of archive etc etc. I can do it? Thanks Daniele
8
5768
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
2781
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 edges like delete, add ... 3) provides a list of all successors/predecessors for a given node 4) provides a list of all nodes that can be reached from a given
8
2448
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 it's not flexible enough anymore and I need something more advanced. I already have a data structure in mind, but I don't know how to implement that nicely in C++. // Main class which holds the lists with // edges and vertices. These lists are...
3
2142
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 internal circuitry that is represented in the form of a graph. I have to abstract the graph by reducing the number of internal points and constructing cumulative paths from each input to every possible output in case a path exists (a series...
10
4323
by: diffuser78 | last post by:
Is there any library in Python which has implementation of graph theoretic algorithms and models ?
0
2130
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 from http://www.boost.org/libs/graph/example/dfs-example.cpp): int main() {
1
3167
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> #include <boost/graph/depth_first_search.hpp> #include <fstream> #include <utility> #include <boost/graph/breadth_first_search.hpp> #include <algorithm>
0
8984
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8237
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.