Commit fd5f4506 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Clean G2/ctos related computation.

	*  apps/g2/CMakeLists.txt,
	*  apps/g2/compute_ctos-cli.cpp: New.
	*  apps/g2/compute_ctos.cpp,
	*  apps/g2/compute_ctos.hpp: Add maxtree/mintree merge algorithm.
	*  apps/g2/compute_g2.hpp,
	*  apps/g2/satmaxtree.cpp: Move debug info to std:cerr.
parent 074653ce
link_libraries(${FreeImage_LIBRARIES})
add_library(g2-tools OBJECT routines.cpp compute_g2.cpp)
add_library(g2-tools OBJECT satmaxtree.cpp compute_ctos.cpp routines.cpp compute_g2.cpp)
add_executable(g2-maxdepth g2-maxdepth.cpp $<TARGET_OBJECTS:g2-tools>)
add_executable(g2-maxtree g2-maxtree.cpp $<TARGET_OBJECTS:g2-tools>)
add_executable(compute_ctos-cli compute_ctos-cli.cpp $<TARGET_OBJECTS:g2-tools>)
add_library(g2-tools-16 OBJECT routines.cpp compute_g2.cpp)
add_executable(g2-maxdepth-16 g2-maxdepth.cpp $<TARGET_OBJECTS:g2-tools-16>)
......@@ -10,4 +12,4 @@ add_executable(g2-maxtree-16 g2-maxtree.cpp $<TARGET_OBJECTS:g2-tools-16>)
set_target_properties(g2-tools-16 g2-maxdepth-16 g2-maxtree-16 PROPERTIES COMPILE_DEFINITIONS MLN_INPUT_VALUE_TYPE=mln::rgb16)
add_executable(satmaxtree-cli satmaxtree-cli.cpp satmaxtree.cpp)
add_executable(satmaxtree-cli satmaxtree-cli.cpp $<TARGET_OBJECTS:g2-tools>)
#include <mln/core/image/image2d.hpp>
#include <mln/core/colors.hpp>
#include <mln/morpho/component_tree/io.hpp>
#include "compute_ctos.hpp"
int main(int argc, char** argv)
{
using namespace mln;
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " input(color) out.tree [out.tiff]\n"
"Compute the cToS of an image. It ouputs the tree (out.tree)"
"and an optional depth image (out.tiff). The tree is computed on"
"K1 (doubled-sized image + border) and so is the depth image";
std::exit(1);
}
image2d<rgb8> f;
io::imread(argv[1], f);
image2d<uint16> depth;
image2d<uint16>* depthptr = (argc > 3) ? &depth : NULL;
auto tree = compute_ctos(f, depthptr);
morpho::save(tree, argv[2]);
if (argc > 3)
io::imsave(depth, argv[3]);
}
......@@ -70,8 +70,9 @@ namespace mln
}
tree_t compute_ctos(const image2d<rgb8>& input,
image2d<uint16>* imdepth)
tree_t
compute_ctos(const image2d<rgb8>& input,
image2d<uint16>* imdepth)
{
typedef rgb8 value_t;
enum { NTREE = value_t::ndim };
......@@ -122,4 +123,54 @@ namespace mln
return tw;
}
tree_t compute_ctos_from_maxtrees(const image2d<rgb8>& input,
image2d<uint16>* imdepth,
bool mintree)
{
typedef rgb8 value_t;
enum { NTREE = value_t::ndim };
image2d<value_t> f = input; //addborder_marginal(input);
image2d<value_t> F = input; //immerse_k1(f);
/// Compute the marginal tree
tree_t t[NTREE];
tbb::parallel_for(0, (int)NTREE, [&t,&f,mintree](int i){
if (mintree)
t[i] = morpho::mintree_indexes(eval(channel(f, i)), c4);
else
t[i] = morpho::maxtree_indexes(eval(channel(f, i)), c4);
});
/// Compute the graph
Graph<NTREE> g2;
std::array<property_map<tree_t, typename MyGraph::vertex_descriptor>, NTREE> tlink;
std::tie(g2, tlink) = compute_g2<NTREE>(t);
/// Compute depth
boost::vector_property_map<unsigned> gdepth;
gdepth = compute_graph_depth(g2);
/// Compute the pw depth image from graph
image2d<uint16> maxdepth;
resize(maxdepth, F);
write_vmap_to_image(g2, t, &tlink[0], gdepth,
functional::max_t<unsigned> (), uint16(0), maxdepth);
/// Compute the saturated maxtree
tree_t tw;
tw = morpho::maxtree_indexes(maxdepth, c4);
/// Outputs the depth image
if (imdepth) {
*imdepth = maxdepth;
}
return tw;
}
}
......@@ -21,6 +21,11 @@ namespace mln
image2d<uint16>* depth = nullptr);
morpho::component_tree<unsigned, image2d<unsigned> >
compute_ctos_from_maxtrees(const image2d<rgb8>& input,
image2d<uint16>* imdepth,
bool mintree = false);
}
#endif // ! APPS_G2_COMPUTE_CTOS_HPP
......@@ -84,7 +84,7 @@ namespace mln
// 2. Build the graph
mln_entering("mln::compute_g2 - graph-construction - vertices");
for (unsigned i = 0; i < NTREE; ++i)
std::cout << "T" << i << ": " << trees[i].realsize() << std::endl;
std::cerr << "T" << i << ": " << trees[i].realsize() << std::endl;
typedef Graph<NTREE> MyGraph;
typedef graph_content<NTREE> my_graph_content;
......@@ -229,7 +229,7 @@ namespace mln
// Some stat
std::cout << "Graph: " << boost::num_vertices(graph) << std::endl;
std::cerr << "Graph: " << boost::num_vertices(graph) << std::endl;
mln_exiting();
return std::tie(graph, tlink);
......
......@@ -51,7 +51,7 @@ namespace mln
mln_foreach(auto x, tree.nodes_without_root()) {
vmap[x] += delta[x];
}
std::cout << "Number of nodes before: " << n << std::endl;
std::cerr << "Number of nodes before: " << n << std::endl;
}
morpho::filter_direct_inplace(tree, pred);
......@@ -62,7 +62,7 @@ namespace mln
assert(vmap[x] > vmap[x.parent()]);
++n;
}
std::cout << "Number of nodes after: " << n << std::endl;
std::cerr << "Number of nodes after: " << n << std::endl;
}
mln_exiting();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment