https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some source to get binaries.
* theo/exec: New directory.
* theo/exec/filetype.hh: New.
* theo/exec/elementary_gradient.cc: New.
* theo/exec/closing_volume.cc: New.
* theo/exec/watershed_flooding.cc: New.
* theo/esiee/laurent/ismm09/topo_wst.cc (echo): New.
(L): Change from 16 to 32 bit.
* theo/esiee/laurent/ismm09/pseudo_tree.hh: Use echo.
esiee/laurent/ismm09/pseudo_tree.hh | 7 +-
esiee/laurent/ismm09/topo_wst.cc | 27 +++++++---
exec/closing_volume.cc | 60 ++++++++++++++++++++++
exec/elementary_gradient.cc | 90 +++++++++++++++++++++++++++++++++
exec/filetype.hh | 54 ++++++++++++++++++++
exec/watershed_flooding.cc | 96 ++++++++++++++++++++++++++++++++++++
6 files changed, 326 insertions(+), 8 deletions(-)
Index: theo/exec/filetype.hh
--- theo/exec/filetype.hh (revision 0)
+++ theo/exec/filetype.hh (revision 0)
@@ -0,0 +1,54 @@
+#include <string>
+
+// 2d
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+// 3d
+#include <mln/core/image/image3d.hh>
+#include <mln/core/alias/neighb3d.hh>
+
+
+// pbm
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+// pgm
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+// ppm
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+
+
+//dump
+#include <mln/io/dump/load.hh>
+#include <mln/io/dump/save.hh>
+
+
+namespace mln
+{
+
+ namespace filetype
+ {
+ enum id { pbm, pgm, ppm, dump, unknown };
+ }
+
+ filetype::id
+ get_filetype(const std::string& filename)
+ {
+ if (filename.find(".pbm") == filename.length() - 4)
+ return filetype::pbm;
+ if (filename.find(".pgm") == filename.length() - 4)
+ return filetype::pgm;
+ if (filename.find(".ppm") == filename.length() - 4)
+ return filetype::ppm;
+ if (filename.find(".dump") == filename.length() - 5)
+ return filetype::dump;
+ return filetype::unknown;
+ }
+
+} // mln
+
+
Index: theo/exec/elementary_gradient.cc
--- theo/exec/elementary_gradient.cc (revision 0)
+++ theo/exec/elementary_gradient.cc (revision 0)
@@ -0,0 +1,90 @@
+#include "filetype.hh"
+#include <mln/morpho/elementary/gradient.hh>
+#include <mln/morpho/elementary/gradient_internal.hh>
+#include <mln/morpho/elementary/gradient_external.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx kind
output.xxx" << std::endl
+ << " Elementary gradient." << std::endl
+ << " kind is 0 (external), 1 (internal), or 2 (thick)." <<
std::endl
+ << " xxx in { pgm, dump }" << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ std::string filename = argv[1];
+ int kind = std::atoi(argv[2]);
+ if (kind < 0 || kind > 2)
+ {
+ std::cerr << "bad kind!" << std::endl;
+ usage(argv);
+ }
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima, grad;
+ io::pgm::load(ima, argv[1]);
+ switch (kind)
+ {
+ case 0:
+ grad = morpho::elementary::gradient_external(ima, c4());
+ break;
+ case 1:
+ grad = morpho::elementary::gradient_internal(ima, c4());
+ break;
+ case 2:
+ grad = morpho::elementary::gradient(ima, c4());
+ break;
+ }
+ io::pgm::save(grad, argv[3]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<int_u8> ima, grad;
+ io::dump::load(ima, argv[1]);
+ switch (kind)
+ {
+ case 0:
+ grad = morpho::elementary::gradient_external(ima, c6());
+ break;
+ case 1:
+ grad = morpho::elementary::gradient_internal(ima, c6());
+ break;
+ case 2:
+ grad = morpho::elementary::gradient(ima, c6());
+ break;
+ }
+ io::dump::save(grad, argv[3]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
Index: theo/exec/closing_volume.cc
--- theo/exec/closing_volume.cc (revision 0)
+++ theo/exec/closing_volume.cc (revision 0)
@@ -0,0 +1,60 @@
+#include "filetype.hh"
+#include <mln/morpho/closing_volume.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx
lambda output.xxx" << std::endl
+ << " Volume closing." << std::endl
+ << " xxx in { pgm, dump }" << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ std::string filename = argv[1];
+ unsigned lambda = atoi(argv[2]);
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima, clo;
+ io::pgm::load(ima, argv[1]);
+ clo = morpho::closing_volume(ima, c4(), lambda);
+ io::pgm::save(clo, argv[3]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<int_u8> ima, clo;
+ io::dump::load(ima, argv[1]);
+ clo = morpho::closing_volume(ima, c6(), lambda);
+ io::dump::save(clo, argv[3]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
Index: theo/exec/watershed_flooding.cc
--- theo/exec/watershed_flooding.cc (revision 0)
+++ theo/exec/watershed_flooding.cc (revision 0)
@@ -0,0 +1,96 @@
+#include "filetype.hh"
+
+#include <mln/morpho/watershed/flooding.hh>
+#include <mln/value/label_16.hh>
+
+#include <mln/level/transform.hh>
+#include <mln/convert/to_fun.hh>
+
+
+namespace mln
+{
+
+ mln::value::int_u8 L_to_int_u8(unsigned u)
+ {
+ return u == 0 ?
+ 0 : // wshed line
+ 1 + (u - 1) % 255; // basin
+ }
+
+} // mln
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx
output.yyy" << std::endl
+ << " Watershed flooding." << std::endl
+ << " xxx in { pgm, dump }" << std::endl
+ << " yyy in { pbm, pgm, dump }" << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ typedef value::label_16 L;
+ if (argc != 3)
+ usage(argv);
+
+ trace::entering("main");
+
+ std::string filename = argv[1];
+ L n_basins;
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima;
+ io::pgm::load(ima, argv[1]);
+ image2d<L> wst = morpho::watershed::flooding(ima, c4(), n_basins);
+ if (get_filetype(argv[2]) == filetype::dump)
+ {
+ io::dump::save(wst, argv[2]);
+ }
+ else if (get_filetype(argv[2]) == filetype::pgm)
+ {
+ io::pgm::save( level::transform(wst, convert::to_fun(L_to_int_u8)),
+ argv[2] );
+ }
+ else if (get_filetype(argv[2]) == filetype::pbm)
+ {
+ io::pbm::save( (pw::value(wst) == 0u) | wst.domain(),
+ argv[2] );
+ }
+ else
+ {
+ std::cerr << "Bad output file format!" << std::endl;
+ std::abort();
+ }
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<int_u8> ima;
+ io::dump::load(ima, argv[1]);
+ image3d<L> wst = morpho::watershed::flooding(ima, c6(), n_basins);
+ io::dump::save(wst, argv[2]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
Index: theo/esiee/laurent/ismm09/topo_wst.cc
--- theo/esiee/laurent/ismm09/topo_wst.cc (revision 3365)
+++ theo/esiee/laurent/ismm09/topo_wst.cc (working copy)
@@ -1,7 +1,7 @@
#include <mln/core/var.hh>
-#include <mln/value/label_16.hh>
+#include <mln/value/label.hh>
#include <mln/value/int_u8.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
@@ -17,8 +17,9 @@
void usage(char* argv[])
{
- std::cerr << "usage: " << argv[0] << " input.pgm"
<< std::endl;
+ std::cerr << "usage: " << argv[0] << " input.pgm
echo" << std::endl;
std::cerr << "Laurent topological watershed transform thru ISMM 2009
scheme." << std::endl;
+ std::cerr << "echo = 0 (none) or 1 (effective)." << std::endl;
abort();
}
@@ -29,27 +30,38 @@
{
using namespace mln;
using value::int_u8;
- using value::label_16;
- if (argc != 2)
+
+ if (argc != 3)
usage(argv);
+ int echo = std::atoi(argv[2]);
+ if (echo != 0 && echo != 1)
+ {
+ std::cerr << "Bad 'echo' value!" << std::endl;
+ usage(argv);
+ }
+
+
// f: regular image.
image2d<int_u8> f;
io::pgm::load(f, argv[1]);
+
+ if (echo)
debug::println("f:", f);
// g: weights on edges.
mln_VAR(g, cplx2d::f_to_g(f) );
+ if (echo)
debug::println("g:", g);
// r: one pixel is one region.
- typedef label_16 L;
+ typedef value::label<32> L;
L l_max = f.nsites();
image2d<L> w_ext(2 * f.nrows() - 1, 2 * f.ncols() - 1);
@@ -61,6 +73,7 @@
for_all(p)
w_pixel(p) = ++l;
}
+ if (echo)
debug::println("w_ext:", w_ext);
@@ -83,6 +96,7 @@
util::array<L> l_ = sort_by_increasing_attributes(a, l_max);
+ if (echo)
{
std::cout << "l_:" << std::endl;
for (unsigned i = 1; i <= l_max; ++i)
@@ -95,5 +109,6 @@
// -> pseudo-tree
- compute_pseudo_tree(w_ext, g, l_, a, e_to_l1_l2);
+ compute_pseudo_tree(w_ext, g, l_, a, e_to_l1_l2,
+ echo);
}
Index: theo/esiee/laurent/ismm09/pseudo_tree.hh
--- theo/esiee/laurent/ismm09/pseudo_tree.hh (revision 3365)
+++ theo/esiee/laurent/ismm09/pseudo_tree.hh (working copy)
@@ -212,7 +212,8 @@
const G& g, // FIXME: Directly input g_line?
const util::array<L>& l_,
const util::array<A>& a,
- const F& e_to_l1_l2)
+ const F& e_to_l1_l2,
+ bool echo = true)
{
typedef mln_value(G) T; // <--- Type of edge values.
@@ -303,6 +304,7 @@
epar(e) = e;
z_epar(e) = e;
}
+ if (echo)
debug::println("epar (init):", epar); // epar(e) == e so we depict the
edges!
}
@@ -455,7 +457,7 @@
} // end of "for every region with increasing attribute"
-
+ if (echo)
{
// Display 'aa' over all edges.
@@ -543,6 +545,7 @@
aa_line),
c4().win()),
aa_line);
+ if (echo)
debug::println("aa ext:", aa_ext);
}