Commit 263a95e5 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Merge branch 'development/header-guard' into 'development/ranges'

Remove header guards

See merge request !50
parents f13ac5b6 f25233ac
#include <mln/io/imread.hpp>
#include <mln/morpho/component_tree/accumulate.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
#include <mln/accu/accumulators/accu_if.hpp>
#include <mln/accu/accumulators/count.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/topology.hpp>
#include <mln/io/imsave.hpp>
#include "attributes.hpp"
#include "cMSER.hpp"
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/topology.hpp>
#include <mln/accu/accumulators/accu_if.hpp>
#include <mln/accu/accumulators/count.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/component_tree/accumulate.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
int main(int argc, char** argv)
......@@ -16,12 +17,11 @@ int main(int argc, char** argv)
using namespace mln;
po::options_description desc("MSER Options");
desc.add_options()
("eps,h", po::value<float>()->required(), "The height for neighbor lookup (e.g. 10).")
("export-rec", po::value<std::string>(), "For reconstruction.");
desc.add_options()("eps,h", po::value<float>()->required(), "The height for neighbor lookup (e.g. 10).")(
"export-rec", po::value<std::string>(), "For reconstruction.");
po::variables_map vm = process_cmdline(argc, argv, desc);
tree_t tree = preprocess(vm);
po::variables_map vm = process_cmdline(argc, argv, desc);
tree_t tree = preprocess(vm);
image2d<float> f;
io::imread(vm["input_path"].as<std::string>(), f, true);
......@@ -30,9 +30,7 @@ int main(int argc, char** argv)
auto vmap = morpho::make_attribute_map_from_image(tree, F);
accu::accumulators::accu_if< accu::accumulators::count<>,
K1::is_face_2_t,
point2d > counter;
accu::accumulators::accu_if<accu::accumulators::count<>, K1::is_face_2_t, point2d> counter;
auto amap = morpho::paccumulate(tree, F, counter);
auto amser = compute_MSER(tree, vmap, amap, vm["eps"].as<float>(), MSER_NORM);
......@@ -40,15 +38,15 @@ int main(int argc, char** argv)
auto smap = postprocess(vm, tree, amser);
const char* names[] = {"MSER", "Extinction"};
std::function<float(tree_t::node_type)> attrs[] = { _as_fun(amser), _as_fun(smap) };
const char* names[] = {"MSER", "Extinction"};
std::function<float(tree_t::node_type)> attrs[] = {_as_fun(amser), _as_fun(smap)};
export_(vm, tree, smap, names, attrs, 2);
if (vm.count("export-rec")) {
if (vm.count("export-rec"))
{
auto vmap = morpho::make_attribute_map_from_image(tree, F);
morpho::reconstruction(tree, vmap, F);
io::imsave(F, vm["export-rec"].as<std::string>());
}
}
#ifndef APPS_ATTRIBUTES_MSER_HPP
#define APPS_ATTRIBUTES_MSER_HPP
#pragma once
#include <mln/core/image/image2d.hpp>
#include <mln/core/trace.hpp>
......@@ -135,5 +134,3 @@ mln::image2d<float> compute_MSER_attribute(const mln::image2d<V>& f, const mln::
mln_exiting();
return mser;
}
#endif // ! APPS_ATTRIBUTES_MSER_HPP
#include "MSERArgparser.hpp"
#include <boost/program_options.hpp>
MSERArgParser::MSERArgParser()
: m_desc("MSER options")
{
......
#ifndef APPS_ATTRIBUTES_MSERARGPARSER_HPP
#define APPS_ATTRIBUTES_MSERARGPARSER_HPP
#pragma once
#include "MSER.hpp"
#include "argparser.hpp"
#include <apps/tos/topology.hpp>
#include <boost/program_options/errors.hpp>
#include <boost/program_options/variables_map.hpp>
#include <string>
class MSERArgParser : public AttributeArgParser
{
public:
......@@ -66,5 +69,3 @@ mln::image2d<float> MSERArgParser::run(const boost::program_options::variables_m
});
return eval(attr);
}
#endif // ! APPS_ATTRIBUTES_MSERARGPARSER_HPP
#ifndef APPS_ATTRIBUTES_ARGPARSER_HPP
#define APPS_ATTRIBUTES_ARGPARSER_HPP
#pragma once
#include <boost/program_options/options_description.hpp>
......@@ -8,5 +7,3 @@ class AttributeArgParser
public:
virtual boost::program_options::options_description& description() = 0;
};
#endif // ! APPS_ATTRIBUTES_ARGPARSER_HPP
#include "attributes.hpp"
#include <apps/tos/croutines.hpp>
#include <mln/morpho/extinction.hpp>
#include <mln/morpho/component_tree/io.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/component_tree/compute_depth.hpp>
#include <mln/morpho/component_tree/filtering.hpp>
#include <mln/morpho/component_tree/io.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
#include <mln/morpho/component_tree/compute_depth.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/extinction.hpp>
namespace mln
{
po::variables_map
process_cmdline(int argc, char** argv, po::options_description desc_, const char* usage)
po::variables_map process_cmdline(int argc, char** argv, po::options_description desc_, const char* usage)
{
po::options_description hidden("Allowed options");
hidden.add_options()
("tree_path", po::value<std::string>()->required(), "Input tree")
("input_path", po::value<std::string>()->required(), "Input file (gray level)")
;
hidden.add_options()("tree_path", po::value<std::string>()->required(),
"Input tree")("input_path", po::value<std::string>()->required(), "Input file (gray level)");
po::options_description desc("General options");
desc.add_options()
("help", "Help message")
("grain,g", po::value<int>(), "Perform a grain filter before anything else");
desc.add_options()("help", "Help message")("grain,g", po::value<int>(),
"Perform a grain filter before anything else");
po::options_description desc2("Extinction Options");
desc2.add_options()
("clip", po::value<float>(), "Clip the energy map to [0, t₁]")
("ethreshold", po::value<float>(), "Remove nodes whose extinction ≤ t")
;
desc2.add_options()("clip", po::value<float>(), "Clip the energy map to [0, t₁]")(
"ethreshold", po::value<float>(), "Remove nodes whose extinction ≤ t");
po::options_description desc3("Output Options");
desc3.add_options()
("output-tree", po::value<std::string>(), "Path to save the tree.")
("output-saliency", po::value<std::string>(), "Path to save the saliency map")
("output-csv", po::value<std::string>(), "Path to the csv file to save the attributes")
("output-simp-tree", po::value<std::string>(), "Path to save the simplified tree.")
("output-simp-depth", po::value<std::string>(), "Path to save the simplified tree depth image.")
;
desc3.add_options()("output-tree", po::value<std::string>(), "Path to save the tree.")(
"output-saliency", po::value<std::string>(), "Path to save the saliency map")(
"output-csv", po::value<std::string>(), "Path to the csv file to save the attributes")(
"output-simp-tree", po::value<std::string>(), "Path to save the simplified tree.")(
"output-simp-depth", po::value<std::string>(), "Path to save the simplified tree depth image.");
po::positional_options_description pd;
pd.add("tree_path", 1)
.add("input_path", 1)
;
pd.add("tree_path", 1).add("input_path", 1);
po::options_description all("Allowed options");
po::options_description visible("Allowed options");
......@@ -51,33 +44,29 @@ namespace mln
visible.add(desc_).add(desc).add(desc2).add(desc3);
po::variables_map vm;
try {
po::store(po::command_line_parser(argc, argv)
.options(all)
.positional(pd).run(), vm);
try
{
po::store(po::command_line_parser(argc, argv).options(all).positional(pd).run(), vm);
po::notify(vm);
} catch (...) {
std::cerr << "Usage: " << argv[0] << " input.tree input.tiff [options]\n"
<< usage
<< visible;
}
catch (...)
{
std::cerr << "Usage: " << argv[0] << " input.tree input.tiff [options]\n" << usage << visible;
std::exit(1);
}
if (vm.count("help"))
{
std::cerr << "Usage: " << argv[0] << " input.tree input.tiff [options]\n"
<< usage
<< visible;
std::exit(1);
{
std::cerr << "Usage: " << argv[0] << " input.tree input.tiff [options]\n" << usage << visible;
std::exit(1);
}
return vm;
}
tree_t
preprocess(const po::variables_map& vm)
tree_t preprocess(const po::variables_map& vm)
{
tree_t tree;
morpho::load(vm["tree_path"].as<std::string>(), tree);
......@@ -92,17 +81,15 @@ namespace mln
}
property_map<tree_t, float>
postprocess(const po::variables_map& vm,
const tree_t& tree,
const property_map<tree_t, float>& energy)
property_map<tree_t, float> postprocess(const po::variables_map& vm, const tree_t& tree,
const property_map<tree_t, float>& energy)
{
// convert to image and filter
auto ienergy = morpho::make_image(tree, energy);
if (vm.count("clip"))
{
float threshold1 = vm["clip"].as<float>();
mln_foreach(float& v, ienergy.values())
mln_foreach (float& v, ienergy.values())
if (v > threshold1)
v = threshold1;
}
......@@ -112,28 +99,24 @@ namespace mln
property_map<tree_t, float> vmap = std::move(extincted.get_vmap());
if (vm.count("ethreshold"))
{
float t = vm["ethreshold"].as<float>();
mln_foreach(auto x, tree.nodes())
if (vmap[x] < t)
vmap[x] = 0;
}
{
float t = vm["ethreshold"].as<float>();
mln_foreach (auto x, tree.nodes())
if (vmap[x] < t)
vmap[x] = 0;
}
return vmap;
}
void export_(const po::variables_map& vm,
tree_t& tree,
const property_map<tree_t, float>& saliency_map,
const char* names[],
std::function<float(tree_t::node_type)> vmaps[],
int sz)
void export_(const po::variables_map& vm, tree_t& tree, const property_map<tree_t, float>& saliency_map,
const char* names[], std::function<float(tree_t::node_type)> vmaps[], int sz)
{
mln_entering("export_");
{
int nnodes = 0;
mln_foreach(auto x, tree.nodes())
mln_foreach (auto x, tree.nodes())
if (saliency_map[x] > 0)
nnodes++;
......@@ -142,49 +125,42 @@ namespace mln
if (vm.count("output-saliency"))
{
image2d<float> sal = set_value_on_contour(tree, saliency_map);
io::imsave(sal, vm["output-saliency"].as<std::string>());
}
{
image2d<float> sal = set_value_on_contour(tree, saliency_map);
io::imsave(sal, vm["output-saliency"].as<std::string>());
}
if (vm.count("output-csv"))
{
std::ofstream f(vm["output-csv"].as<std::string>());
for (int i = 0; i < sz; ++i)
f << names[i] << ((i+1 < sz) ? ',' : '\n');
{
std::ofstream f(vm["output-csv"].as<std::string>());
for (int i = 0; i < sz; ++i)
f << names[i] << ((i + 1 < sz) ? ',' : '\n');
mln_foreach(auto x, tree.nodes())
for (int i = 0; i < sz; ++i)
f << vmaps[i](x) << ((i+1 < sz) ? ',' : '\n');
}
mln_foreach (auto x, tree.nodes())
for (int i = 0; i < sz; ++i)
f << vmaps[i](x) << ((i + 1 < sz) ? ',' : '\n');
}
if (vm.count("output-simp-tree") or
vm.count("output-simp-depth") or
vm.count("export-rec"))
{
auto binmap = make_functional_property_map<tree_t::vertex_id_t>
([&saliency_map](tree_t::vertex_id_t x) -> bool {
return saliency_map[x] > 0;
});
if (vm.count("output-simp-tree") or vm.count("output-simp-depth") or vm.count("export-rec"))
{
auto binmap = make_functional_property_map<tree_t::vertex_id_t>(
[&saliency_map](tree_t::vertex_id_t x) -> bool { return saliency_map[x] > 0; });
morpho::filter_direct_inplace(tree, binmap);
morpho::filter_direct_inplace(tree, binmap);
if (vm.count("output-simp-tree"))
morpho::save(tree, vm["output-simp-tree"].as<std::string>());
if (vm.count("output-simp-tree"))
morpho::save(tree, vm["output-simp-tree"].as<std::string>());
if (vm.count("output-simp-depth"))
{
auto depth = morpho::compute_depth(tree);
image2d<uint16> d;
d.resize(tree._get_data()->m_pmap.domain());
morpho::reconstruction(tree, depth, d);
io::imsave(d, vm["output-simp-depth"].as<std::string>());
}
if (vm.count("output-simp-depth"))
{
auto depth = morpho::compute_depth(tree);
image2d<uint16> d;
d.resize(tree._get_data()->m_pmap.domain());
morpho::reconstruction(tree, depth, d);
io::imsave(d, vm["output-simp-depth"].as<std::string>());
}
}
mln_exiting();
}
}
} // namespace mln
#ifndef APPS_ATTRIBUTE_ATTRIBUTES_HPP
# define APPS_ATTRIBUTE_ATTRIBUTES_HPP
#pragma once
#include <mln/core/image/image2d.hpp>
#include <mln/morpho/component_tree/component_tree.hpp>
#include <boost/program_options.hpp>
# include <boost/program_options.hpp>
# include <mln/core/image/image2d.hpp>
# include <mln/morpho/component_tree/component_tree.hpp>
namespace po = boost::program_options;
typedef mln::morpho::component_tree<unsigned, mln::image2d<unsigned> > tree_t;
typedef mln::morpho::component_tree<unsigned, mln::image2d<unsigned>> tree_t;
namespace mln
{
po::variables_map
process_cmdline(int argc, char** argv, po::options_description desc, const char* usage = "");
po::variables_map process_cmdline(int argc, char** argv, po::options_description desc, const char* usage = "");
tree_t
preprocess(const po::variables_map& vm);
tree_t preprocess(const po::variables_map& vm);
property_map<tree_t, float>
postprocess(const po::variables_map& vm,
const tree_t& tree,
const property_map<tree_t, float>& energy);
property_map<tree_t, float> postprocess(const po::variables_map& vm, const tree_t& tree,
const property_map<tree_t, float>& energy);
void export_(const po::variables_map& vm,
tree_t& tree,
const property_map<tree_t, float>& saliency_map,
const char* names[],
std::function<float(tree_t::node_type)> vmaps[],
int sz);
void export_(const po::variables_map& vm, tree_t& tree, const property_map<tree_t, float>& saliency_map,
const char* names[], std::function<float(tree_t::node_type)> vmaps[], int sz);
template <class Amap>
std::function<float(tree_t::node_type)> _as_fun(const Amap& w) {
std::function<float(tree_t::node_type)> _as_fun(const Amap& w)
{
return [&w](tree_t::node_type x) -> float { return w[x]; };
}
}
#endif // ! APPS_ATTRIBUTE_ATTRIBUTES_HPP
} // namespace mln
#ifndef APPS_ATTRIBUTE_CMSER_HPP
#define APPS_ATTRIBUTE_CMSER_HPP
#pragma once
#include <mln/core/trace.hpp>
#include <mln/morpho/component_tree/component_tree.hpp>
enum eMSER_attribute
{
MSER_DIFF, // Val > 0, δΓ = A(Γ⁺) - A(Γ⁻)
......@@ -110,6 +110,4 @@ namespace mln
return compute_MSER(tree, vmap, amap, eps, amser, fsum, dist);
}
}
#endif // ! APPS_ATTRIBUTE_CMSER_HPP
} // namespace mln
#ifndef APPS_ATTRIBUTE_CMEANINGFULLNESS_HPP
#define APPS_ATTRIBUTE_CMEANINGFULLNESS_HPP
#pragma once
#include "curvature.hpp"
#include <apps/g2/accu/lca.hpp>
#include <apps/tos/croutines.hpp>
#include <apps/tos/topology.hpp>
#include <mln/accu/accumulator.hpp>
#include <mln/accu/accumulators/mean.hpp>
#include <mln/accu/accumulators/variance.hpp>
......@@ -14,6 +15,7 @@
#include <mln/morpho/component_tree/component_tree.hpp>
#include <mln/morpho/component_tree/compute_depth.hpp>
namespace mln
{
......@@ -181,6 +183,4 @@ namespace mln
return energy;
}
}
#endif // ! APPS_ATTRIBUTE_CMEANINGFULLNESS_HPP
} // namespace mln
#include <mln/io/imread.hpp>
#include <mln/morpho/component_tree/accumulate.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
#include <mln/accu/accumulators/mean.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/topology.hpp>
#include <apps/tos/croutines.hpp>
#include <mln/io/imsave.hpp>
#include "attributes.hpp"
#include "circularity.hpp"
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/croutines.hpp>
#include <apps/tos/topology.hpp>
#include <mln/accu/accumulators/mean.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/component_tree/accumulate.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
int main(int argc, char** argv)
......@@ -18,15 +17,14 @@ int main(int argc, char** argv)
using namespace mln;
po::options_description desc("Circularity Options");
desc.add_options()
("export-rec", po::value<std::string>(), "For reconstruction.");
desc.add_options()("export-rec", po::value<std::string>(), "For reconstruction.");
// desc.add_options()
// ("eps,h", po::value<float>()->required(), "The height for neighbor lookup (e.g. 10).")
// ("export-rec", po::value<std::string>(), "For reconstruction.");
po::variables_map vm = process_cmdline(argc, argv, desc);
tree_t tree = preprocess(vm);
po::variables_map vm = process_cmdline(argc, argv, desc);
tree_t tree = preprocess(vm);
image2d<rgb8> f;
io::imread(vm["input_path"].as<std::string>(), f, true);
......@@ -34,35 +32,31 @@ int main(int argc, char** argv)
image2d<rgb8> F = Kadjust_to(f, tree._get_data()->m_pmap.domain());
auto perimeter = compute_attribute_on_contour(tree, F, accu::features::count<>());
auto area = morpho::accumulate(tree, accu::features::count<>());
auto circu = circularity(tree);
auto area = morpho::accumulate(tree, accu::features::count<>());
auto circu = circularity(tree);
constexpr float coefnorm = 2 * 1.7724538509055159; // 2.(pi^.5)
property_map<tree_t, float> vmap(tree);
mln_foreach(auto x, tree.nodes())
{
vmap[x] = perimeter[x] / (coefnorm*std::sqrt(area[x])) + circu[x];
}
mln_foreach (auto x, tree.nodes())
{
vmap[x] = perimeter[x] / (coefnorm * std::sqrt(area[x])) + circu[x];
}
auto smap = postprocess(vm, tree, vmap);
auto pa = make_functional_property_map<tree_t::node_type>([&area,&perimeter](const tree_t::node_type& x) {
return perimeter[x] / (coefnorm*std::sqrt(area[x]));
});
auto pa = make_functional_property_map<tree_t::node_type>(
[&area, &perimeter](const tree_t::node_type& x) { return perimeter[x] / (coefnorm * std::sqrt(area[x])); });
const char* names[] = {"Circularity", "P/A", "Energy", "Extinction"};
std::function<float(tree_t::node_type)> attrs[] = {
_as_fun(circu), _as_fun(pa),
_as_fun(vmap), _as_fun(smap)
};
const char* names[] = {"Circularity", "P/A", "Energy", "Extinction"};
std::function<float(tree_t::node_type)> attrs[] = {_as_fun(circu), _as_fun(pa), _as_fun(vmap), _as_fun(smap)};
export_(vm, tree, smap, names, attrs, 4);
if (vm.count("export-rec")) {
auto vmap = morpho::vaccumulate_proper(tree, F, accu::features::mean<> ());
if (vm.count("export-rec"))
{
auto vmap = morpho::vaccumulate_proper(tree, F, accu::features::mean<>());
morpho::reconstruction(tree, vmap, F);
io::imsave(F, vm["export-rec"].as<std::string>());
}
}
#include "circularity.hpp"
#include <mln/morpho/component_tree/accumulate.hpp>
#include <mln/accu/accumulators/covariance.hpp>
#include <mln/accu/accumulators/covariance.hpp>
#include <mln/morpho/component_tree/accumulate.hpp>
mln::property_map<tree_t, float>
circularity(const tree_t& tree)
mln::property_map<tree_t, float> circularity(const tree_t& tree)
{
using namespace mln;
......@@ -18,25 +17,28 @@ circularity(const tree_t& tree)
property_map<tree_t, float> vmap(tree);