Skip to content

Commit

Permalink
added code to cut a hierarchy in 2 parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Camille authored and Camille committed Oct 24, 2011
1 parent ba1091e commit 208e180
Show file tree
Hide file tree
Showing 7 changed files with 726 additions and 9 deletions.
19 changes: 19 additions & 0 deletions generic/imgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ static int imgraph_(mergetree)(lua_State *L) {
t->cs = cs;
t->rs = rs;
t->altitudes = altitudes;



return 1;
}

Expand Down Expand Up @@ -714,6 +717,21 @@ static int imgraph_(filtertree)(lua_State *L) {
return 1;
}


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);

// done
return 1;
}

static int imgraph_(weighttree)(lua_State *L) {
// get args
MergeTree *t = lua_toMergeTree(L, 1);
Expand Down Expand Up @@ -1376,6 +1394,7 @@ static const struct luaL_Reg imgraph_(methods__) [] = {
{"tree2components", imgraph_(tree2components)},
{"adjacency", imgraph_(adjacency)},
{"segm2components", imgraph_(segm2components)},
{"cuttree", imgraph_(cuttree)},
{NULL, NULL}
};

Expand Down
38 changes: 30 additions & 8 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,28 @@ function imgraph.weighttree(...)
torch.Tensor().imgraph.weighttree(tree, weights)
end

----------------------------------------------------------------------
-- computes a cut in a tree
--
function imgraph.cuttree(...)
--get args
local args = {...}
local tree = args[1]
local weights = args[2]

-- usage
if not tree or not weights 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}))
xlua.error('incorrect arguments', 'imgraph.cuttree')
end

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

----------------------------------------------------------------------
-- transform a merge tree back into a graph, for visualization
--
Expand Down Expand Up @@ -752,14 +774,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
7 changes: 7 additions & 0 deletions mergetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ typedef struct {
int rs;
} MergeTree;

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


static MergeTree *lua_toMergeTree (lua_State *L, int index)
{
MergeTree *mt = (MergeTree *)lua_touserdata(L, index);
Expand Down
4 changes: 3 additions & 1 deletion pink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ add_library(pink
mcindic.c
mclifo.c
mcfifo.c
mcunionfind.c)
mcunionfind.c
mtrand64.c
kruskal.c)

set (CMAKE_C_FLAGS "-fpic -g -DUNIXIO")
target_link_libraries(pink)
Loading

0 comments on commit 208e180

Please sign in to comment.