Commit 8b4184c9 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add utils for the interactive segmentation.

	*  apps/supervised-gui/CMakeLists.txt,
	*  apps/supervised-gui/automatic.cpp,
	*  apps/supervised-gui/supervised-cli-multi.cpp,
	*  apps/supervised-gui/supervised-gui-3c.cpp,
	*  apps/supervised-gui/compute_distance.hpp: Add debug msg.
	*  apps/supervised-gui/generate_res.cpp,
	*  apps/supervised-gui/nettoyage.cpp: New.
parent d92c9310
......@@ -15,6 +15,8 @@ if(QT4_FOUND)
add_executable(supervised-cli supervised-cli.cpp)
add_executable(supervised-cli-multi supervised-cli-multi.cpp)
add_executable(automatic automatic.cpp)
add_executable(nettoyage nettoyage.cpp)
add_executable(generate_res generate_res.cpp)
add_executable(supervised-gui-3c supervised-gui-3c.cpp brush.cpp
${supervised_MOC}
......@@ -24,6 +26,7 @@ if(QT4_FOUND)
target_link_libraries(supervised-gui-3c ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})
target_link_libraries(supervised-cli ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})
target_link_libraries(nettoyage ${Boost_PROGRAM_OPTIONS_LIBRARIES})
set_property(TARGET supervised-cli-multi APPEND PROPERTY INCLUDE_DIRECTORIES "/work/carlinet/src/eigen/")
......
......@@ -67,6 +67,9 @@ int main(int argc, char** argv)
morpho::reconstruction(tree, avmap, out);
std::cout << "See: /tmp/alpha.tiff" << std::endl;
io::imsave(out, "/tmp/alpha.tiff");
// Get the seeds.
unsigned area_threshold = std::atoi(argv[3]);
property_map<tree_t, uint8> active(tree, true);
......@@ -137,6 +140,8 @@ int main(int argc, char** argv)
ske = morpho::area_closing(ske, c8, 20);
transform::chamfer_distance_transform(ske, c4, ske);
std::cout << "See: " << stem << ".ske.pgm\n";
io::imsave(ske, stem + ".ske.pgm");
......@@ -175,6 +180,10 @@ int main(int argc, char** argv)
}
}
// Clean Remove small CC
imlabel = morpho::area_opening(imlabel, c8, 100);
io::imsave(imlabel, argv[5]);
std::cout << "See: " << stem << ".markers.tiff\n";
io::imsave(out, stem + ".markers.tiff");
}
......@@ -2,6 +2,7 @@
# define COMPUTE_DISTANCE_HPP
# include "constants.hpp"
# include <mln/colors/lab.hpp>
typedef mln::morpho::component_tree<unsigned, mln::image2d<unsigned> > tree_t;
......@@ -28,12 +29,14 @@ compute_distance(const tree_t& tree,
distancemap[tree.npos()] = value_traits<float>::sup();
//auto mydist = [](rgb8 a, rgb8 b) -> float { return l2norm(rgb2lab(a) - rgb2lab(b)); };
auto mydist = [](rgb8 a, rgb8 b) -> float { return l2norm(a - b); };
// Upward
mln_reverse_foreach(auto x, tree.nodes_without_root())
{
// Note the 0.1
// The distance must stricly > 0
float tmp = distancemap[x] + l2norm(vmap[x] - vmap[x.parent()]) + 0.1;
float tmp = distancemap[x] + mydist(vmap[x], vmap[x.parent()]) + 0.1;
if (tmp < distancemap[x.parent()])
distancemap[x.parent()] = tmp;
}
......@@ -43,7 +46,7 @@ compute_distance(const tree_t& tree,
mln_foreach(auto x, tree.nodes_without_root())
{
// The distance must stricly > 0
float tmp = distancemap[x.parent()] + l2norm(vmap[x] - vmap[x.parent()]) + 0.1;
float tmp = distancemap[x.parent()] + mydist(vmap[x], vmap[x.parent()]) + 0.1;
if (tmp < distancemap[x])
distancemap[x] = tmp;
}
......
#include <mln/core/image/image2d.hpp>
#include <mln/core/se/ball.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/structural/gradient.hpp>
#include <mln/core/algorithm/fill.hpp>
#include <mln/colors/literal.hpp>
int main(int argc, char** argv)
{
using namespace mln;
if (argc < 4) {
std::cerr << "Usage: " << argv[0] << " rec.ppm marked.ppm out.ppm\n"
;
std::exit(1);
}
image2d<rgb8> F, M;
io::imread(argv[1], F);
io::imread(argv[2], M);
se::ball2d b = se::make_ball2d(5.3);
image2d<bool> M2;
M2 = morpho::structural::external_gradient(M != rgb8(literal::zero), b,
productorder_less<bool> (),
[] (int x) -> bool { return x != 0; }
);
fill(F | M2, colors::literal::white);
io::imsave(F, argv[3]);
}
#include <mln/core/image/image2d.hpp>
#include <mln/core/neighb2d.hpp>
#include <mln/core/algorithm/paste.hpp>
#include <mln/core/algorithm/copy.hpp>
#include <mln/morpho/saturate.hpp>
#include <mln/labeling/blobs.hpp>
#include <mln/labeling/accumulate.hpp>
#include <mln/accu/accumulators/count.hpp>
#include <mln/colors/literal.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main(int argc, char** argv)
{
using namespace mln;
po::options_description desc("Allowed options");
desc.add_options()
("no-sat", "do not saturate")
;
po::options_description hidden;
desc.add_options()
("mask.pbm", po::value<std::string> ())
("input.ppm", po::value<std::string> ())
("out.ppm", po::value<std::string> ())
;
po::positional_options_description pd;
pd.add("mask.pbm", 1)
.add("input.ppm", 1)
.add("out.ppm", 1);
po::options_description allopt;
allopt.add(desc).add(hidden);
po::variables_map vm;
try {
po::store(po::basic_command_line_parser<char>(argc, argv).options(allopt).positional(pd).run(), vm);
po::notify(vm);
}
catch (...) {
std::cout << "Usage: " << argv[0] << " [--no-sat] mask.pbm input.ppm output.ppm\n"
<< "Keep only the largest CC and saturate\n";
std::exit(1);
}
image2d<bool> mask;
image2d<rgb8> f;
io::imread(vm["mask.pbm"].as<std::string> (), mask);
io::imread(vm["input.ppm"].as<std::string> (), f);
uint16 nlabel;
image2d<uint16> lbl;
mask = eval(lnot(mask));
std::tie(lbl, nlabel) = labeling::blobs(mask, c8, (uint16)0);
auto res = labeling::p_accumulate(lbl, nlabel, accu::features::count<> ());
res[0] = 0;
std::vector<int> idx(nlabel);
std::iota(idx.begin(), idx.end(), 0);
std::sort(idx.begin(), idx.end(), [&res](int i, int j) { return res[i] > res[j]; });
int obj = idx[0];
fill(mask, false);
for (int i = 0; (i < nlabel) and (res[idx[i]] >= 0.5 * res[obj]); ++i)
{
std::cout << "Objet: " << idx[i] << " / " << nlabel << std::endl;
fill((mask | (lbl == idx[i])), true);
}
if (vm.count("no-sat") == 0)
{
box2d dom2 = mask.domain();
dom2.pmin -= 1;
dom2.pmax += 1;
image2d<bool> mask2(dom2, 3, false);
paste(mask, mask2);
mask2 = morpho::saturate(mask2, c8, point2d{-1,-1});
copy(mask2 | mask.domain(), mask);
}
fill(f | lnot(mask), colors::literal::black);
io::imsave(f, vm["out.ppm"].as<std::string> ());
}
......@@ -144,7 +144,6 @@ int main(int argc, char** argv)
image2d<rgb8> seg;
int nlabel = accumulate(markers, accu::features::max<> ());
res = segmentation(tree, vmap, markers, nlabel);
for (int i = 1; i <= nlabel; ++i) {
auto clo = morpho::area_closing(res == i, c4, grain);
fill(res | clo, i);
......
......@@ -147,6 +147,7 @@ segmentation(const tree_t& tree,
image2d<rgb8> out = clone(original);
fill(out | (markers_ == BACKGROUND), colors::literal::red);
fill(out | (markers_ == FOREGROUND), colors::literal::blue);
std::cout << "See /tmp/markers_.tiff for the image marked" << std::endl;
io::imsave(out, "/tmp/markers_.tiff");
}
......@@ -154,6 +155,7 @@ segmentation(const tree_t& tree,
image2d<uint8> out;
resize(out, tree._get_data()->m_pmap);
morpho::reconstruction(tree, colormap, out);
std::cout << "See /tmp/markers.tiff for tree markers" << std::endl;
io::imsave(out, "/tmp/markers.tiff");
}
......@@ -161,8 +163,20 @@ segmentation(const tree_t& tree,
image2d< rgb<float> > out;
resize(out, tree._get_data()->m_pmap);
morpho::reconstruction(tree, dmap, out);
std::cout << "See /tmp/distances.tiff for distances" << std::endl;
io::imsave(out, "/tmp/distances.tiff");
}
{
auto bmap = make_functional_property_map<tree_t::node_type>
([&cmap] (const tree_t::node_type& x) -> bool { return cmap[x] == FOREGROUND; });
image2d<bool> out;
resize(out, tree._get_data()->m_pmap);
morpho::reconstruction(tree, bmap, out);
out = Kadjust_to(out, markers__.domain());
std::cout << "See /tmp/mask.pbm for mask" << std::endl;
io::imsave(out, "/tmp/mask.pbm");
}
}
......@@ -186,6 +200,7 @@ segmentation(const tree_t& tree,
if (trace::verbose)
{
std::cout << "See /tmp/segmented.png for distances" << std::endl;
io::imsave(output, "/tmp/segmented.png");
}
......
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