Commit 7315a3d2 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Work on morphological attributes. Add new 'circularity' attribute and

add 'ethreshold' parameter for thresholding extinction maps.

    *  apps/attributes/CMakeLists.txt: Fixed.
    *  apps/attributes/MSER-cli.cpp: Add reconstruction parameter.
    *  apps/attributes/attributes.cpp: Add ethreshold parameter.
    *  apps/attributes/circularity-cli.cpp,
    *  apps/attributes/circularity.cpp,
    *  apps/attributes/circularity.hpp: New.
parent a9d1f034
......@@ -5,5 +5,8 @@ add_executable(stat stat.cpp)
add_executable(MSER-cli MSER-cli.cpp attributes.cpp)
add_executable(meaningfullness-cli meaningfullness-cli.cpp curvature.cpp attributes.cpp)
add_executable(circularity-cli circularity-cli.cpp circularity.cpp attributes.cpp)
target_link_libraries(MSER-cli ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries(meaningfullness-cli ${Boost_PROGRAM_OPTIONS_LIBRARY})
\ No newline at end of file
target_link_libraries(meaningfullness-cli ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries(circularity-cli ${Boost_PROGRAM_OPTIONS_LIBRARY})
\ No newline at end of file
#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"
......@@ -15,7 +17,8 @@ int main(int argc, char** argv)
po::options_description desc("MSER Options");
desc.add_options()
("eps,h", po::value<float>()->required(), "The height for neighbor lookup (e.g. 10).");
("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);
......@@ -41,4 +44,11 @@ int main(int argc, char** argv)
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")) {
auto vmap = morpho::make_attribute_map_from_image(tree, F);
morpho::reconstruction(tree, vmap, F);
io::imsave(F, vm["export-rec"].as<std::string>());
}
}
......@@ -27,7 +27,9 @@ namespace mln
po::options_description desc2("Extinction Options");
desc2.add_options()
("clip", po::value<float>(), "Clip the energy map to [0, t₁]");
("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()
......@@ -108,6 +110,15 @@ namespace mln
auto extincted = morpho::extinction(ienergy, morpho::tree_neighb_t());
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;
}
return vmap;
}
......
#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"
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()
// ("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);
image2d<rgb8> f;
io::imread(vm["input_path"].as<std::string>(), f, true);
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);
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];
}
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]));
});
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<> ());
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>
mln::property_map<tree_t, float>
circularity(const tree_t& tree)
{
using namespace mln;
mln_entering("compute_circularity");
accu::accumulators::covariance<point2d, double> COV;
auto covmap = morpho::paccumulate(tree, tree._get_data()->m_pmap, COV);
property_map<tree_t, float> vmap(tree);
mln_foreach(auto x, tree.nodes())
{
auto cov = covmap[x];
double T = cov(0,0) + cov(1,1);
double D = cov(0,0) * cov(1,1) - cov(0,1) * cov(1,0);
double tmp = sqrt(T*T/4-D);
double l1, l2;
if (tmp > 0) {
l1 = T/2 + tmp;
l2 = T/2 - tmp;
} else {
l2 = T/2 + tmp;
l1 = T/2 - tmp;
}
vmap[x] = 1 - l2 / l1;
}
mln_exiting();
return vmap;
}
#ifndef APPS_ATTRIBUTES_CIRCULARITY_HPP
# define APPS_ATTRIBUTES_CIRCULARITY_HPP
# include "attributes.hpp"
/// \brief Compute the ratio of the principal axes
///
/// C(x) = 1 - (λ₂ / λ₁)
/// where: λ₁, λ₂ are the two major scale parameters
///
/// C(x) = 0 ⇒ Circle/Square
/// C(x) → 1 ⇒ Elongated object
mln::property_map<tree_t, float>
circularity(const tree_t& tree);
#endif // ! APPS_ATTRIBUTES_CIRCULARITY_HPP
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