Commit 54064d33 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Small improvements in G2 computation.

	*  apps/g2/compute_ctos-cli.cpp: Add grain filtering option.
	*  apps/g2/compute_ctos.cpp,
	*  apps/g2/compute_ctos.hpp: Make it generic with value types.
	*  apps/g2/satmaxtree.cpp: Better memory management.
parent 4d12d309
#include <mln/core/image/image2d.hpp>
#include <mln/core/colors.hpp>
#include <mln/morpho/component_tree/io.hpp>
#include <mln/morpho/component_tree/compute_depth.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
#include "compute_ctos.hpp"
#include <apps/tos/croutines.hpp>
int main(int argc, char** argv)
{
......@@ -11,22 +13,29 @@ int main(int argc, char** argv)
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " input(color) out.tree [out.tiff]\n"
std::cerr << "Usage: " << argv[0] << " input(color) out.tree [out.tiff] [grain]\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";
"and an optional depth image (out.tiff). The tree is computed on "
"K1 (doubled-sized image + border) and so is the depth image\n"
"If a grain is given, a grain filter is applied.\n";
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, NULL);
auto tree = compute_ctos(f, depthptr);
if (argc > 4)
grain_filter_inplace(tree, std::atoi(argv[4]));
morpho::save(tree, argv[2]);
if (argc > 3)
if (argc > 3) {
image2d<uint16> depth;
depth.resize(tree._get_data()->m_pmap.domain());
auto dmap = morpho::compute_depth(tree);
morpho::reconstruction(tree, dmap, depth);
io::imsave(depth, argv[3]);
}
}
......@@ -70,42 +70,45 @@ namespace mln
}
template <class V>
tree_t
compute_ctos(const image2d<rgb8>& input,
compute_ctos(const image2d<V>& input,
image2d<uint16>* imdepth)
{
typedef rgb8 value_t;
typedef V value_t;
enum { NTREE = value_t::ndim };
image2d<value_t> f = addborder_marginal(input);
image2d<value_t> F = immerse_k1(f);
image2d<uint16> maxdepth;
point2d pmin = {0,0};
/// Compute the marginal tree
tree_t t[NTREE];
tbb::parallel_for(0, (int)NTREE, [&t,&f,pmin](int i){
t[i] = morpho::cToS_pinf(imtransform(f, [i](value_t x) {
return x[i]; }), c4, pmin);
});
{
/// Compute the marginal tree
tree_t t[NTREE];
tbb::parallel_for(0, (int)NTREE, [&t,&f,pmin](int i){
t[i] = morpho::cToS_pinf(imtransform(f, [i](value_t x) {
return x[i]; }), c4, pmin);
});
/// 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 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 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 pw depth image from graph
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;
......@@ -173,4 +176,16 @@ namespace mln
return tw;
}
// Explicit instanciation.
template
tree_t
compute_ctos<rgb8>(const image2d<rgb8>& input,
image2d<uint16>* imdepth);
// Explicit instanciation.
template
tree_t
compute_ctos<rgb16>(const image2d<rgb16>& input,
image2d<uint16>* imdepth);
}
......@@ -16,8 +16,9 @@ namespace mln
///
/// \param input The input image
/// \param[out] depth if not NULL, store the depth image inside.
template <class V>
morpho::component_tree<unsigned, image2d<unsigned> >
compute_ctos(const image2d<rgb8>& input,
compute_ctos(const image2d<V>& input,
image2d<uint16>* depth = nullptr);
......@@ -26,6 +27,16 @@ namespace mln
image2d<uint16>* imdepth,
bool mintree = false);
extern template
morpho::component_tree<unsigned, image2d<unsigned> >
compute_ctos<rgb8>(const image2d<rgb8>& input,
image2d<uint16>* depth = nullptr);
extern template
morpho::component_tree<unsigned, image2d<unsigned> >
compute_ctos<rgb16>(const image2d<rgb16>& input,
image2d<uint16>* depth = nullptr);
}
#endif // ! APPS_G2_COMPUTE_CTOS_HPP
......@@ -28,9 +28,13 @@ namespace mln
// }
T tree = morpho::cToS_pinf(f, c4, pmin);
image2d<uint16> F = immerse_k1(f, 69);
property_map<T, uint16> vmap = morpho::make_attribute_map_from_image(tree, F);
vmap[tree.npos()] = 0;
property_map<T, uint16> vmap;
{
image2d<uint16> F = immerse_k1(f, 69);
vmap = morpho::make_attribute_map_from_image(tree, F);
vmap[tree.npos()] = 0;
}
auto predfun = [&vmap,&tree](const T::vertex_id_t& n) {
return vmap[n] > vmap[tree.get_node(n).parent()] or tree.get_node(n).get_parent_id() == tree.npos();
......
Markdown is supported
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