Skip to content

Commit

Permalink
Added table extractor for Kruskal code.
Browse files Browse the repository at this point in the history
  • Loading branch information
clementfarabet committed Oct 25, 2011
1 parent 208e180 commit 957b882
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 54 deletions.
16 changes: 11 additions & 5 deletions generic/imgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,15 +721,21 @@ static int imgraph_(filtertree)(lua_State *L) {
static int imgraph_(cuttree)(lua_State *L) {
// get args
MergeTree *t = lua_toMergeTree(L, 1);
int table_weights = 2; // arg 2


//calling the labeling method on the merge tree
list * cut;
cut = MSF_Kruskal(t);
list * cut = MSF_Kruskal(t);

// export list into lua table
lua_newtable(L); int tb = lua_gettop(L);
int id = 1;
while(cut) {
lua_pushnumber(L, cut->index);
lua_rawseti(L, tb, id++);
cut = cut->next;
}

// done
return 1;
return 1;
}

static int imgraph_(weighttree)(lua_State *L) {
Expand Down
1 change: 1 addition & 0 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "lwshedtopo.h"
#include "lsaliency.h"
#include "lhierarchie.h"
#include "kruskal.h"
#include "llpeGA.h"
#include "lga2khalimsky.h"
#include "lppm2GA.h"
Expand Down
24 changes: 11 additions & 13 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,17 @@ function imgraph.cuttree(...)
--get args
local args = {...}
local tree = args[1]
local weights = args[2]

-- usage
if not tree or not weights then
if not tree then
print(xlua.usage('imgraph.cuttree',
'computes a cut in a tree', nil,
{type='imgraph.MergeTree', help='merge tree to be weighted', req=true},
{type='table', help='a list of weights t[k] = w, with k the index of the node to be weighted', req=true}))
{type='imgraph.MergeTree', help='merge tree to be weighted', req=true}))
xlua.error('incorrect arguments', 'imgraph.cuttree')
end

-- compute cut
torch.Tensor().imgraph.cuttree(tree, weights)
return torch.Tensor().imgraph.cuttree(tree)
end

----------------------------------------------------------------------
Expand Down Expand Up @@ -774,14 +772,14 @@ imgraph._example = [[
local mt = imgraph.mergetree(graph)
-- (7) display results
image.display{image=inputimg, legend='input image'}
image.display{image=cc, legend='thresholded graph'}
image.display{image=watershed, legend='watershed on the graph'}
image.display{image=watershedcc, legend='components of watershed'}
image.display{image=mstsegmcolor, legend='segmented graph, using min-spanning tree'}
image.display{image=pool, legend='original imaged hist-pooled by segmentation'}
image.display{image=hierarchy, legend='raw edge-weighted graph watershed'}
image.display{image=filteredhierarchy, legend='filtered edge-weighted graph watershed'}
image.display{image=inputimg, legend='input image'}
image.display{image=cc, legend='thresholded graph'}
image.display{image=watershed, legend='watershed on the graph'}
image.display{image=watershedcc, legend='components of watershed'}
image.display{image=mstsegmcolor, legend='segmented graph, using min-spanning tree'}
image.display{image=pool, legend='original imaged hist-pooled by segmentation'}
image.display{image=hierarchy, legend='raw edge-weighted graph watershed'}
image.display{image=filteredhierarchy, legend='filtered edge-weighted graph watershed'}
]]
function imgraph.testme(usrimg)
local inputimg
Expand Down
18 changes: 7 additions & 11 deletions mergetree.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#ifndef _MERGETREE_
#define _MERGETREE_

// create a proper Lua class to represent a merge tree
#define MT "imgraph.MergeTree"

#ifndef _MERGETREESTRUCT_
#define _MERGETREESTRUCT_
typedef struct {
mtree *tree;
RAG *rag;
Expand All @@ -13,13 +9,13 @@ typedef struct {
int cs;
int rs;
} MergeTree;
#endif

typedef struct list
{
int index;
struct list *next;
} list ;
#ifndef _MERGETREE_
#define _MERGETREE_

// create a proper Lua class to represent a merge tree
#define MT "imgraph.MergeTree"

static MergeTree *lua_toMergeTree (lua_State *L, int index)
{
Expand Down
26 changes: 1 addition & 25 deletions pink/kruskal.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,11 @@ author: Camille Couprie
#include <jcgraphes.h>
#include <jccomptree.h>
#include <mtrand64.h>
#include "kruskal.h"

#define false 0
#define true 1

typedef struct {
mtree *tree;
RAG *rag;
struct xvimage *labels;
int32_t *altitudes;
float *weights;
int cs;
int rs;
} MergeTree;

typedef struct list
{
int index;
struct list *next;
} list ;


void Insert(list **sl, int index)
{
list *tmp = NULL;
Expand All @@ -55,14 +39,6 @@ void Insert(list **sl, int index)
else *sl = elem;
}

void PrintList(list *sl);
int element_link( int x,int y, uint32_t *Rnk, uint32_t *Fth);
int element_find(int x, uint32_t *Fth );
void TriRapideStochastique_dec (float * A, uint32_t *I, long p, long r);
long PartitionStochastique_dec (float *A, uint32_t * I, long p, long r);
int nb_neighbors(int x, JCctree *CT, int nb_leafs);
int neighbor(int x, int k, JCctree *CT, int nb_leafs, int * SeededNodes);

/*=====================================================================================*/
list * MSF_Kruskal(MergeTree * MT) // max_weight /* maximum weight value */ )
/*=====================================================================================*/
Expand Down
31 changes: 31 additions & 0 deletions pink/kruskal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#ifndef _MERGETREESTRUCT_
#define _MERGETREESTRUCT_
typedef struct {
mtree *tree;
RAG *rag;
struct xvimage *labels;
int32_t *altitudes;
float *weights;
int cs;
int rs;
} MergeTree;
#endif

typedef struct list
{
int index;
struct list *next;
} list ;

void Insert(list **sl, int index);

void PrintList(list *sl);
int element_link( int x,int y, uint32_t *Rnk, uint32_t *Fth);
int element_find(int x, uint32_t *Fth );
void TriRapideStochastique_dec (float * A, uint32_t *I, long p, long r);
long PartitionStochastique_dec (float *A, uint32_t * I, long p, long r);
int nb_neighbors(int x, JCctree *CT, int nb_leafs);
int neighbor(int x, int k, JCctree *CT, int nb_leafs, int * SeededNodes);

list * MSF_Kruskal(MergeTree * MT);

0 comments on commit 957b882

Please sign in to comment.