3121: Re-enable tests in morpho and make them work again.

* tests/morpho/Makefile.am: re-enable all tests. * tests/morpho/artificial_line_graph_image_wst.cc, * tests/morpho/graph_image_morpho.cc, * tests/morpho/graph_image_wst.cc, * tests/morpho/lena_line_graph_image_wst1.cc, * tests/morpho/lena_line_graph_image_wst2.cc, * tests/morpho/line_graph_image_morpho.cc, * tests/morpho/line_graph_image_wst.cc: update according the new graph structures. --- milena/ChangeLog | 15 +++ milena/tests/morpho/Makefile.am | 35 +++--- .../morpho/artificial_line_graph_image_wst.cc | 40 ++++---- milena/tests/morpho/graph_image_morpho.cc | 99 ++++++++---------- milena/tests/morpho/graph_image_wst.cc | 78 ++++++++------ milena/tests/morpho/lena_line_graph_image_wst1.cc | 89 ++++++++-------- milena/tests/morpho/lena_line_graph_image_wst2.cc | 37 +++---- milena/tests/morpho/line_graph_image_morpho.cc | 91 ++++++++-------- milena/tests/morpho/line_graph_image_wst.cc | 115 +++++++++++--------- 9 files changed, 311 insertions(+), 288 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index c42010f..8952f82 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,20 @@ 2008-12-31 Guillaume Lazzara <z@lrde.epita.fr> + Re-enable tests in morpho and make them work again. + + * tests/morpho/Makefile.am: re-enable all tests. + + * tests/morpho/artificial_line_graph_image_wst.cc, + * tests/morpho/graph_image_morpho.cc, + * tests/morpho/graph_image_wst.cc, + * tests/morpho/lena_line_graph_image_wst1.cc, + * tests/morpho/lena_line_graph_image_wst2.cc, + * tests/morpho/line_graph_image_morpho.cc, + * tests/morpho/line_graph_image_wst.cc: update according the new graph + structures. + +2008-12-31 Guillaume Lazzara <z@lrde.epita.fr> + Re-enable tools/area_flooding. * tools/Makefile.am: enable the target. diff --git a/milena/tests/morpho/Makefile.am b/milena/tests/morpho/Makefile.am index a8f12ab..003ba6f 100644 --- a/milena/tests/morpho/Makefile.am +++ b/milena/tests/morpho/Makefile.am @@ -2,13 +2,12 @@ include $(top_srcdir)/milena/tests/tests.mk -##FIXME: re-enable all tests SUBDIRS = \ elementary \ tree check_PROGRAMS = \ -## artificial_line_graph_image_wst \ + artificial_line_graph_image_wst \ closing_area \ closing_height \ closing_volume \ @@ -20,14 +19,14 @@ check_PROGRAMS = \ erosion \ general \ gradient \ -## graph_image_morpho \ -## graph_image_wst \ + graph_image_morpho \ + graph_image_wst \ hit_or_miss \ laplacian \ -## lena_line_graph_image_wst1 \ -## lena_line_graph_image_wst2 \ -## line_graph_image_wst \ -## line_graph_image_morpho \ + lena_line_graph_image_wst1 \ + lena_line_graph_image_wst2 \ + line_graph_image_wst \ + line_graph_image_morpho \ meyer_wst \ meyer_wst_long \ opening_area \ @@ -58,11 +57,11 @@ hit_or_miss_SOURCES = hit_or_miss.cc laplacian_SOURCES = laplacian.cc thinning_SOURCES = thinning.cc -##graph_image_morpho_SOURCES = graph_image_morpho.cc -##graph_image_wst_SOURCES = graph_image_wst.cc +graph_image_morpho_SOURCES = graph_image_morpho.cc +graph_image_wst_SOURCES = graph_image_wst.cc -##line_graph_image_morpho_SOURCES = line_graph_image_morpho.cc -##line_graph_image_wst_SOURCES = line_graph_image_wst.cc +line_graph_image_morpho_SOURCES = line_graph_image_morpho.cc +line_graph_image_wst_SOURCES = line_graph_image_wst.cc complex_image_morpho_SOURCES = complex_image_morpho.cc complex_image_wst_SOURCES = complex_image_wst.cc @@ -79,17 +78,17 @@ combined_SOURCES = combined.cc # Complex tests. # # --------------- # -##artificial_line_graph_image_wst_SOURCES = artificial_line_graph_image_wst.cc -##artificial_line_graph_image_wst_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) +artificial_line_graph_image_wst_SOURCES = artificial_line_graph_image_wst.cc +artificial_line_graph_image_wst_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) dilation_SOURCES = dilation.cc dilation_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) -##lena_line_graph_image_wst1_SOURCES = lena_line_graph_image_wst1.cc -##lena_line_graph_image_wst1_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) +lena_line_graph_image_wst1_SOURCES = lena_line_graph_image_wst1.cc +lena_line_graph_image_wst1_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) -##lena_line_graph_image_wst2_SOURCES = lena_line_graph_image_wst2.cc -##lena_line_graph_image_wst2_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) +lena_line_graph_image_wst2_SOURCES = lena_line_graph_image_wst2.cc +lena_line_graph_image_wst2_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) meyer_wst_long_SOURCES = meyer_wst_long.cc meyer_wst_long_CXXFLAGS = $(TESTS_CXXFLAGS_SPEED) diff --git a/milena/tests/morpho/artificial_line_graph_image_wst.cc b/milena/tests/morpho/artificial_line_graph_image_wst.cc index ebdfaa1..c88ac15 100644 --- a/milena/tests/morpho/artificial_line_graph_image_wst.cc +++ b/milena/tests/morpho/artificial_line_graph_image_wst.cc @@ -47,16 +47,18 @@ in it, interpolating inter-pixel points; \li print the watershed on lines into that same image, and save it. */ -#include <vector> - #include <mln/core/image/image2d.hh> #include <mln/core/alias/point2d.hh> #include <mln/core/alias/window2d.hh> #include <mln/core/alias/neighb2d.hh> -#include <mln/core/image/line_graph_image.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> -#include <mln/core/image/line_graph_neighborhood_piter.hh> +/// Required for line graph images. +#include <mln/core/site_set/p_edges.hh> +#include <mln/core/image/line_graph_elt_window.hh> +#include <mln/core/var.hh> +#include <mln/pw/all.hh> +#include <mln/fun/i2v/array.hh> +#include <mln/util/graph.hh> #include <mln/morpho/line_gradient.hh> #include <mln/morpho/closing_area_on_vertices.hh> @@ -114,27 +116,25 @@ int main() `----------------*/ // Line graph image. - typedef line_graph_image<point2d, input_val_t> ima_t; - ima_t lg_ima = morpho::line_gradient(input); + mln_VAR(lg_ima, morpho::line_gradient(input)); /*------. | WST. | `------*/ - typedef line_graph_elt_neighborhood<point2d> nbh_t; - nbh_t nbh; + typedef line_graph_elt_window<util::graph, lg_ima_t::pset::fun_t> win_t; + win_t win; + neighb<win_t> nbh(win); // Perform a Watershed Transform. - typedef unsigned wst_val_t; - wst_val_t nbasins; - typedef line_graph_image<point2d, wst_val_t> wst_ima_t; - wst_ima_t wshed = morpho::meyer_wst(lg_ima, nbh, nbasins); + unsigned nbasins; + mln_VAR(wshed, morpho::meyer_wst(lg_ima, nbh, nbasins)); std::cout << "nbasins = " << nbasins << std::endl; /*---------. | Output. | `---------*/ - + // FIXME: Inlined conversion, to be reifed into a routine. // Save the result in gray levels (data) + color (wshed). @@ -179,12 +179,12 @@ int main() /* FIXME: We should draw the watershed on another image and superimpose it on OUTPUT instead of drawing it directly into OUTPUT. */ - mln_piter_(wst_ima_t) pw(wshed.domain()); + mln_piter_(wshed_t) pw(wshed.domain()); for_all(pw) { if (wshed(pw) == 0) { - mln_psite_(wst_ima_t) pp(pw); + mln_psite_(lg_ima_t) pp(pw); // Equivalent of the line (edge) PP in OUTPUT. int row1 = pp.first()[0] * 2; int col1 = pp.first()[1] * 2; @@ -192,7 +192,7 @@ int main() int col2 = pp.second()[1] * 2; point2d q((row1 + row2) / 2, (col1 + col2) / 2); // Print the watershed in red. - output(q) = literal::red; + output(q) = literal::red; } } // Fill the holes, so that the watershed looks connected. @@ -212,13 +212,13 @@ int main() // two or more, consider, create a watershed point. /* FIXME: Iterating over a c4 window would be more elegant, of course. */ - unsigned nwsheds = - (output.has(p_out + up ) && output(p_out + up ) == literal::red) + + unsigned nwsheds = + (output.has(p_out + up ) && output(p_out + up ) == literal::red) + (output.has(p_out + down ) && output(p_out + down ) == literal::red) + (output.has(p_out + left ) && output(p_out + right) == literal::red) + (output.has(p_out + right) && output(p_out + left ) == literal::red); if (nwsheds >= 2) - output(p_out) = literal::red; + output(p_out) = literal::red; } io::ppm::save(output, "out.ppm"); } diff --git a/milena/tests/morpho/graph_image_morpho.cc b/milena/tests/morpho/graph_image_morpho.cc index 664533c..8552061 100644 --- a/milena/tests/morpho/graph_image_morpho.cc +++ b/milena/tests/morpho/graph_image_morpho.cc @@ -26,45 +26,29 @@ // Public License. /// \file tests/morpho/graph_image_morpho.cc -/// \brief Tests on mln::graph_image with morphological filters. - -#include <vector> +/// +/// Tests on mln::graph_image with morphological filters. #include <mln/accu/bbox.hh> #include <mln/core/alias/box2d.hh> #include <mln/core/alias/point2d.hh> -#include <mln/core/image/graph_elt_window.hh> -#include <mln/core/image/graph_window_piter.hh> -#include <mln/core/var.hh> #include <mln/morpho/dilation.hh> #include <mln/morpho/erosion.hh> -#include <mln/util/graph.hh> - +/// Required for graph images. +#include <mln/core/site_set/p_vertices.hh> +#include <mln/core/image/graph_elt_window.hh> +#include <mln/core/var.hh> #include <mln/pw/all.hh> +#include <mln/fun/i2v/array.hh> +#include <mln/util/graph.hh> #include <mln/debug/draw_graph.hh> #include <mln/debug/iota.hh> #include <mln/debug/println.hh> -template <typename S> -struct vertex_site_value_t : public mln::Function_p2v< vertex_site_value_t<S> > -{ - typedef unsigned result; - - unsigned - operator()(const mln_psite(S)& p) const - { - return v_[p.v().id()]; - } - - protected: - std::vector<result> v_; -}; - - int main() { using namespace mln; @@ -87,20 +71,21 @@ int main() */ // Points associated to vertices. - typedef fun::i2v::array<point2d> F; - F points(5); - points(0) = point2d(0,0); // Point associated to vertex 0. - points(1) = point2d(2,2); // Point associated to vertex 1. - points(2) = point2d(0,4); // Point associated to vertex 2. - points(3) = point2d(4,3); // Point associated to vertex 3. - points(4) = point2d(4,4); // Point associated to vertex 4. - - // Edges. - typedef mln::util::graph G; - G g; + typedef fun::i2v::array<point2d> fsite_t; + fsite_t sites(5); + sites(0) = point2d(0,0); // Point associated to vertex 0. + sites(1) = point2d(2,2); // Point associated to vertex 1. + sites(2) = point2d(0,4); // Point associated to vertex 2. + sites(3) = point2d(4,3); // Point associated to vertex 3. + sites(4) = point2d(4,4); // Point associated to vertex 4. + + // Graph. + util::graph g; + // Populate the graph with vertices. - for (unsigned i = 0; i < points.size(); ++i) - g.add_vertex (); + for (unsigned i = 0; i < sites.size(); ++i) + g.add_vertex(); + // Populate the graph with edges. g.add_edge(0, 1); g.add_edge(1, 2); @@ -108,21 +93,26 @@ int main() g.add_edge(3, 4); g.add_edge(4, 2); + /*----------------------. | Graph image support. | `----------------------*/ - p_vertices<G, F> pg(g, points); + typedef p_vertices<util::graph, fsite_t> pv_t; + pv_t pv(g, sites); /*--------------. | Graph image. | `--------------*/ - vertex_site_value_t< p_vertices<G, F> > values; - // Graph image. - mln_VAR(ima, (values | pg)); - // Initialize values. - debug::iota(ima); + // Graph values. + typedef fun::i2v::array<unsigned> viota_t; + viota_t iota(pv.nsites()); + for (unsigned i = 0; i < iota.size(); ++i) + iota(i) = 10 + i; + + // Create graph image. + mln_const_VAR(ima, (iota | pv)); /*-------------------------------------. | Image representation/visualization. | @@ -132,12 +122,12 @@ int main() /* FIXME: mln::graph_image should automatically feature a bbox when its parameter P is akin to a point. */ accu::bbox<point2d> a; - for (unsigned i = 0; i < points.size(); ++i) - a.take(points(i)); + for (unsigned i = 0; i < sites.size(); ++i) + a.take(sites(i)); box2d bbox = a.to_result(); // Print the image. /* FIXME: Unfortunately, displaying graph images is not easy right - now (2008-02-05). We could use + now (2008-02-05). We could use debug::println(ima); @@ -146,7 +136,7 @@ int main() interface of graph_image to work with points (not psites). Moreover, this implementation only shows *values*, not the graph itslef. - + An alternative is to use draw::graph (which, again, is misnamed), but it doesn't show the values, only the vertices and edges of the graph. @@ -159,14 +149,13 @@ int main() | Processing graph images. | `--------------------------*/ - typedef graph_elt_window<G, F> win_t; - win_t win; + graph_elt_window<util::graph, fsite_t> win; - image2d<unsigned> ima_dil = morpho::dilation(ima, win); -// debug::draw_graph(ima_rep, ima_dil, 9); -// debug::println(ima_rep); + mln_const_VAR(ima_dil, morpho::dilation(ima, win)); + debug::draw_graph(ima_rep, ima_dil.domain(), pw::cst(9), pw::cst(2)); + debug::println(ima_rep); - image2d<unsigned> ima_ero = morpho::erosion(ima, win); -// draw::graph(ima_rep, ima_ero, 9); -// debug::println(ima_rep); + mln_const_VAR(ima_ero, morpho::erosion(ima, win)); + debug::draw_graph(ima_rep, ima_ero.domain(), pw::cst(9), pw::cst(2)); + debug::println(ima_rep); } diff --git a/milena/tests/morpho/graph_image_wst.cc b/milena/tests/morpho/graph_image_wst.cc index 41dcd5e..53f78cd 100644 --- a/milena/tests/morpho/graph_image_wst.cc +++ b/milena/tests/morpho/graph_image_wst.cc @@ -31,9 +31,15 @@ #include <vector> #include <mln/core/alias/point2d.hh> -#include <mln/core/image/graph_image.hh> -#include <mln/core/image/graph_elt_neighborhood.hh> -#include <mln/core/image/graph_neighborhood_piter.hh> + +/// Required for graph images. +#include <mln/core/site_set/p_vertices.hh> +#include <mln/core/image/graph_elt_window.hh> +#include <mln/core/neighb.hh> +#include <mln/core/var.hh> +#include <mln/pw/all.hh> +#include <mln/fun/i2v/array.hh> +#include <mln/util/graph.hh> #include <mln/morpho/meyer_wst.hh> @@ -60,18 +66,21 @@ int main() */ // Points associated to vertices. - std::vector<point2d> points; - points.push_back(point2d(0,0)); // Point associated to vertex 0. - points.push_back(point2d(2,2)); // Point associated to vertex 1. - points.push_back(point2d(0,4)); // Point associated to vertex 2. - points.push_back(point2d(4,3)); // Point associated to vertex 3. - points.push_back(point2d(4,4)); // Point associated to vertex 4. - - // Edges. - util::graph<point2d> g; + typedef fun::i2v::array<point2d> fsite_t; + fsite_t sites(5); + sites(0) = point2d(0,0); // Point associated to vertex 0. + sites(1) = point2d(2,2); // Point associated to vertex 1. + sites(2) = point2d(0,4); // Point associated to vertex 2. + sites(3) = point2d(4,3); // Point associated to vertex 3. + sites(4) = point2d(4,4); // Point associated to vertex 4. + + // Graph. + util::graph g; + // Populate the graph with vertices. - for (unsigned i = 0; i < points.size(); ++i) - g.add_vertex (points[i]); + for (unsigned i = 0; i < sites.size(); ++i) + g.add_vertex(); + // Populate the graph with edges. g.add_edge(0, 1); g.add_edge(1, 2); @@ -79,42 +88,41 @@ int main() g.add_edge(3, 4); g.add_edge(4, 2); - /*-------. - | Graph. | - `-------*/ - p_graph<point2d> pg(g); + /*----------------------. + | Graph image support. | + `----------------------*/ + + typedef p_vertices<util::graph, fsite_t> pv_t; + pv_t pv(g, sites); /*-------------. | Graph image. | `-------------*/ - // Values. - std::vector<int> values(5); - values[0] = 0; // Value associated to vertex 0. - values[1] = 1; // Value associated to vertex 1. - values[2] = 2; // Value associated to vertex 2. - values[3] = 3; // Value associated to vertex 3. - values[4] = 0; // Value associated to vertex 4. - // Graph image. - typedef graph_image<point2d, int> ima_t; - ima_t ima(pg, values); + // Graph values. + typedef fun::i2v::array<unsigned> viota_t; + viota_t iota(pv.nsites()); + for (unsigned i = 0; i < iota.size(); ++i) + iota(i) = 10 + i; + + // Create graph image. + mln_const_VAR(ima, (iota | pv)); /*------. | WST. | `------*/ - typedef graph_elt_neighborhood<point2d> nbh_t; - nbh_t nbh; + typedef graph_elt_window<util::graph, fsite_t> win_t; + win_t win; + neighb<win_t> nbh(win); - typedef unsigned wst_val_t; - wst_val_t nbasins; - typedef graph_image<point2d, wst_val_t> wst_ima_t; - wst_ima_t wshed = morpho::meyer_wst(ima, nbh, nbasins); + unsigned nbasins; + mln_const_VAR(wshed, morpho::meyer_wst(ima, nbh, nbasins)); std::cout << "nbasins = " << nbasins << std::endl; // Manual iteration over the domain of WSHED. - mln_piter_(wst_ima_t) pw(wshed.domain()); + mln_piter_(wshed_t) pw(wshed.domain()); for_all (pw) std::cout << "wshed (" << pw << ") = " << wshed(pw) << std::endl; } diff --git a/milena/tests/morpho/lena_line_graph_image_wst1.cc b/milena/tests/morpho/lena_line_graph_image_wst1.cc index 95a6c07..d897d96 100644 --- a/milena/tests/morpho/lena_line_graph_image_wst1.cc +++ b/milena/tests/morpho/lena_line_graph_image_wst1.cc @@ -56,9 +56,15 @@ #include <mln/core/alias/window2d.hh> #include <mln/core/alias/neighb2d.hh> -#include <mln/core/image/line_graph_image.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> -#include <mln/core/image/line_graph_neighborhood_piter.hh> +#include <mln/convert/to_window.hh> + +/// Required for line graph images. +#include <mln/core/site_set/p_edges.hh> +#include <mln/core/image/line_graph_elt_window.hh> +#include <mln/core/var.hh> +#include <mln/pw/all.hh> +#include <mln/fun/i2v/array.hh> +#include <mln/util/graph.hh> #include <mln/morpho/gradient.hh> #include <mln/morpho/closing_area.hh> @@ -75,6 +81,8 @@ #include <mln/math/max.hh> #include <mln/math/abs.hh> +#include <mln/util/site_pair.hh> + #include "tests/data.hh" @@ -100,7 +108,7 @@ int main() // Simplify the input image. image2d<input_val_t> work(input.domain()); - morpho::closing_area(gradient, c4(), 10, work); + work = morpho::closing_area(gradient, c4(), 10); /*-------------. | Line graph. | @@ -108,70 +116,61 @@ int main() // FIXME: Inlined conversion, to be reifed into a routine. - util::graph<point2d> g; + util::graph g; // Points. - /* FIXME: The need for such a structure during the conversion - exhibits the lack of a service from util::graph (or a another, - missing tool) regarding the retrieval of vertex ids from - points. */ - std::map<point2d, util::vertex_id, util::ord<point2d> > points; - util::vertex_id id = 0; + image2d<unsigned> equiv_vertex; + initialize(equiv_vertex, work); // Vertices. - std::vector<int> vertex_values; mln_fwd_piter_(image2d<input_val_t>) p(work.domain()); - for_all (p) - { - g.add_vertex (p); - vertex_values.push_back (work(p)); - /* FIXME: ``Guessing'' the id of the point just being inserted - is bad. util:graph<N,E>::add_vertex should return this - id. */ - points[p] = id; - ++id.to_equiv(); - } + for_all(p) + equiv_vertex(p) = g.add_vertex(); // Edges. window2d next_c4_win; next_c4_win.insert(0, 1).insert(1, 0); - std::vector<int> edge_values; - mln_fwd_qiter_(window2d) q(next_c4_win, p); + typedef fun::i2v::array<int> edge_values_t; + typedef fun::i2v::array< util::site_pair<point2d> > edge_sites_t; + edge_values_t edge_values; + edge_sites_t edge_sites; + mln_fwd_qiter_(window2d) q(next_c4_win, p); for_all (p) - for_all (q) - if (work.domain().has(q)) + for_all(q) + if (work.domain().has(q)) { - g.add_edge(points[p], points[q]); - edge_values.push_back(math::max(work(p), work(q))); + unsigned edge_id = g.add_edge(equiv_vertex(p), equiv_vertex(q)); + edge_values.resize(edge_values.size() + 1); + edge_sites.resize(edge_sites.size() + 1); + edge_values(edge_id) = math::max(work(p), work(q)); + edge_sites(edge_id) = util::site_pair<point2d>(p, q); } // Line graph point set. - p_line_graph<point2d> plg(g); - - // Line graph image. - /* FIXME: Shouldn't we use `input_val_t' instead of plain `int' as value - type here? */ - typedef line_graph_image<point2d, int> ima_t; - ima_t lg_ima(plg, vertex_values, edge_values); + typedef p_edges<util::graph, edge_sites_t> pe_t; + pe_t pe(g, edge_sites); + + // Line graph image + typedef pw::image<edge_values_t, pe_t> ima_t; + mln_VAR(lg_ima, (edge_values | pe)); /*------. | WST. | `------*/ - typedef line_graph_elt_neighborhood<point2d> nbh_t; - nbh_t nbh; + typedef line_graph_elt_window<util::graph, edge_sites_t> win_t; + win_t win; + neighb<win_t> nbh; // Perform a Watershed Transform. - typedef int_u8 wst_val_t; - wst_val_t nbasins; - typedef line_graph_image<point2d, wst_val_t> wst_ima_t; - wst_ima_t wshed = morpho::meyer_wst(lg_ima, nbh, nbasins); + int_u8 nbasins; + mln_VAR(wshed, morpho::meyer_wst(lg_ima, nbh, nbasins)); std::cout << "nbasins = " << nbasins << std::endl; /*---------. | Output. | `---------*/ - + // FIXME: Inlined conversion, to be reifed into a routine. // Save the result in gray levels (data) + color (wshed). @@ -216,12 +215,12 @@ int main() /* FIXME: We should draw the watershed on another image and superimpose it on OUTPUT instead of drawing it directly into OUTPUT. */ - mln_piter_(wst_ima_t) pw(wshed.domain()); + mln_piter_(wshed_t) pw(wshed.domain()); for_all(pw) { - if (wshed(pw) == 0) + if (wshed(pw) == 0u) { - mln_psite_(wst_ima_t) pp(pw); + mln_psite_(lg_ima_t) pp(pw); // Equivalent of the line (edge) PP in OUTPUT. int row1 = pp.first()[0] * 2; int col1 = pp.first()[1] * 2; diff --git a/milena/tests/morpho/lena_line_graph_image_wst2.cc b/milena/tests/morpho/lena_line_graph_image_wst2.cc index 7283796..de48d35 100644 --- a/milena/tests/morpho/lena_line_graph_image_wst2.cc +++ b/milena/tests/morpho/lena_line_graph_image_wst2.cc @@ -33,7 +33,7 @@ /** \file tests/morpho/lena_line_graph_image_wst2.cc \brief More tests on the Watershed Transform (WST) on a mln::line_graph_image. - + The scenario is as follows: \li load a 2-D, gray-level image from a PGM file; \li convert this 2-D image into a line graph-based one, where values @@ -49,16 +49,18 @@ in it, interpolating inter-pixel points; \li print the watershed on lines into that same image, and save it. */ -#include <vector> - #include <mln/core/image/image2d.hh> #include <mln/core/alias/point2d.hh> #include <mln/core/alias/window2d.hh> #include <mln/core/alias/neighb2d.hh> -#include <mln/core/image/line_graph_image.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> -#include <mln/core/image/line_graph_neighborhood_piter.hh> +/// Required for line graph images. +#include <mln/core/site_set/p_edges.hh> +#include <mln/core/image/line_graph_elt_window.hh> +#include <mln/core/var.hh> +#include <mln/pw/all.hh> +#include <mln/fun/i2v/array.hh> +#include <mln/util/graph.hh> #include <mln/morpho/line_gradient.hh> #include <mln/morpho/closing_area_on_vertices.hh> @@ -101,34 +103,31 @@ int main() `----------------*/ // Line graph image. - typedef line_graph_image<point2d, input_val_t> ima_t; - ima_t lg_ima = morpho::line_gradient(input); + mln_VAR(lg_ima, morpho::line_gradient(input)); /*-----------------. | Simplification. | `-----------------*/ - typedef line_graph_elt_neighborhood<point2d> nbh_t; - nbh_t nbh; + typedef line_graph_elt_window<util::graph, lg_ima_t::pset::fun_t> win_t; + win_t win; + neighb<win_t> nbh(win); - ima_t closed_lg_ima (lg_ima.domain()); - morpho::closing_area_on_vertices(lg_ima, nbh, 20, closed_lg_ima); + mln_VAR(closed_lg_ima, morpho::closing_area_on_vertices(lg_ima, nbh, 20)); /*------. | WST. | `------*/ // Perform a Watershed Transform. - typedef unsigned wst_val_t; - wst_val_t nbasins; - typedef line_graph_image<point2d, wst_val_t> wst_ima_t; - wst_ima_t wshed = morpho::meyer_wst(closed_lg_ima, nbh, nbasins); + unsigned nbasins; + mln_VAR(wshed, morpho::meyer_wst(closed_lg_ima, nbh, nbasins)); std::cout << "nbasins = " << nbasins << std::endl; /*---------. | Output. | `---------*/ - + // FIXME: Inlined conversion, to be reifed into a routine. // Save the result in gray levels (data) + color (wshed). @@ -173,12 +172,12 @@ int main() /* FIXME: We should draw the watershed on another image and superimpose it on OUTPUT instead of drawing it directly into OUTPUT. */ - mln_piter_(wst_ima_t) pw(wshed.domain()); + mln_piter_(wshed_t) pw(wshed.domain()); for_all(pw) { if (wshed(pw) == 0) { - mln_psite_(wst_ima_t) pp(pw); + mln_psite_(lg_ima_t) pp(pw); // Equivalent of the line (edge) PP in OUTPUT. int row1 = pp.first()[0] * 2; int col1 = pp.first()[1] * 2; diff --git a/milena/tests/morpho/line_graph_image_morpho.cc b/milena/tests/morpho/line_graph_image_morpho.cc index 43bf66b..ce32528 100644 --- a/milena/tests/morpho/line_graph_image_morpho.cc +++ b/milena/tests/morpho/line_graph_image_morpho.cc @@ -26,14 +26,18 @@ // Public License. /// \file tests/morpho/line_graph_image_morpho.cc -/// \brief Tests on mln::line_graph_image with morphological filters. - -#include <vector> +/// +/// Tests on mln::line_graph_image with morphological filters. #include <mln/core/alias/point2d.hh> -#include <mln/core/image/line_graph_image.hh> + +/// Required for line graph images. +#include <mln/core/site_set/p_edges.hh> #include <mln/core/image/line_graph_elt_window.hh> -#include <mln/core/image/line_graph_window_piter.hh> +#include <mln/core/var.hh> +#include <mln/pw/all.hh> +#include <mln/fun/i2v/array.hh> +#include <mln/util/graph.hh> #include <mln/morpho/erosion.hh> #include <mln/morpho/dilation.hh> @@ -51,7 +55,7 @@ int main() 0 1 2 3 4 0 1 2 3 4 .----------- .----------- - | | + | | 0 | 0 2 0 | * * 1 | \ / | 1 | 0 1 | 2 | 1 | 2 | * 4 @@ -60,19 +64,22 @@ int main() */ + // Graph. + util::graph g; + // Points associated to vertices. - std::vector<point2d> points; - points.push_back(point2d(0,0)); // Point associated to vertex 0. - points.push_back(point2d(2,2)); // Point associated to vertex 1. - points.push_back(point2d(0,4)); // Point associated to vertex 2. - points.push_back(point2d(4,3)); // Point associated to vertex 3. - points.push_back(point2d(4,4)); // Point associated to vertex 4. - - // Edges. - util::graph<point2d> g; + typedef fun::i2v::array<point2d> fsite_t; + fsite_t sites(5); + sites(0) = point2d(0,0); // Point associated to vertex 0. + sites(1) = point2d(2,2); // Point associated to vertex 1. + sites(2) = point2d(0,4); // Point associated to vertex 2. + sites(3) = point2d(4,3); // Point associated to vertex 3. + sites(4) = point2d(4,4); // Point associated to vertex 4. + // Populate the graph with vertices. - for (unsigned i = 0; i < points.size(); ++i) - g.add_vertex (points[i]); + for (unsigned i = 0; i < sites.size(); ++i) + g.add_vertex(); + // Populate the graph with edges. g.add_edge(0, 1); g.add_edge(1, 2); @@ -80,48 +87,44 @@ int main() g.add_edge(3, 4); g.add_edge(4, 2); + /*---------------------------. | Line graph image support. | `---------------------------*/ - p_line_graph<point2d> plg(g); + typedef p_edges<util::graph, fsite_t> pe_t; + pe_t pe(g, sites); /*-------------------. | Line graph image. | `-------------------*/ - // Values ("empty" vectors). - std::vector<int> vertex_values(5); - std::vector<int> edge_values(5); - // FIXME: hand-made iota's. - for (unsigned i = 0; i < vertex_values.size(); ++i) - vertex_values[i] = i; - for (unsigned i = 0; i < edge_values.size(); ++i) - edge_values[i] = i; - - // Line graph image. - /* FIXME: We probably don't want to build line_graph_images by hand; - provide helpers and/or conversion functions. */ - typedef line_graph_image<point2d, int> ima_t; - ima_t ima(plg, vertex_values, edge_values); - - /*--------------------------. - | Processing graph images. | - `--------------------------*/ - - typedef line_graph_elt_window<point2d> win_t; - win_t win; - - line_graph_image<point2d, int> ima_dil = morpho::dilation(ima, win); + // Line graph values. + typedef fun::i2v::array<unsigned> viota_t; + viota_t iota(pe.nsites()); + for (unsigned i = 0; i < iota.size(); ++i) + iota(i) = 10 + i; + + // Create line graph image. + mln_const_VAR(ima, (iota | pe)); + + + /*-------------------------------. + | Processing line graph images. | + `-------------------------------*/ + + line_graph_elt_window<util::graph, fsite_t> win; + + mln_const_VAR(ima_dil, morpho::dilation(ima, win)); // Manual iteration over the domain of IMA_DIL. - mln_piter_(ima_t) p_dil(ima_dil.domain()); + mln_piter_(ima_dil_t) p_dil(ima_dil.domain()); for_all (p_dil) std::cout << "ima_dil (" << p_dil << ") = " << ima_dil(p_dil) << std::endl; std::cout << std::endl; - line_graph_image<point2d, int> ima_ero = morpho::erosion(ima, win); + mln_const_VAR(ima_ero, morpho::erosion(ima, win)); // Manual iteration over the domain of IMA_ERO. - mln_piter_(ima_t) p_ero(ima_ero.domain()); + mln_piter_(ima_ero_t) p_ero(ima_ero.domain()); for_all (p_ero) std::cout << "ima_ero (" << p_ero << ") = " << ima_ero(p_ero) << std::endl; } diff --git a/milena/tests/morpho/line_graph_image_wst.cc b/milena/tests/morpho/line_graph_image_wst.cc index ce6514f..a700d16 100644 --- a/milena/tests/morpho/line_graph_image_wst.cc +++ b/milena/tests/morpho/line_graph_image_wst.cc @@ -26,14 +26,19 @@ // Public License. /// \file tests/morpho/line_graph_image_wst.cc -/// \brief Tests on the Watershed Transform on a mln::line_graph_image. - -#include <vector> +/// +/// Tests on the Watershed Transform on a mln::line_graph_image. #include <mln/core/alias/point2d.hh> -#include <mln/core/image/line_graph_image.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> -#include <mln/core/image/line_graph_neighborhood_piter.hh> + +/// Required for line graph images. +#include <mln/core/site_set/p_edges.hh> +#include <mln/core/image/line_graph_elt_window.hh> +#include <mln/core/neighb.hh> +#include <mln/core/var.hh> +#include <mln/pw/all.hh> +#include <mln/fun/i2v/array.hh> +#include <mln/util/graph.hh> #include <mln/morpho/meyer_wst.hh> @@ -61,45 +66,52 @@ int main() In G, vertices and egdes are numbered following in the classical foward order. */ - util::graph<point2d> g; - - // Vertices. - std::vector<int> vertex_values; - // We don't really care about values on vertices, because the algorithm - // won't see them. So all are set to 0. - g.add_vertex (point2d(0, 0)); vertex_values.push_back (0); // Vertex 0. - g.add_vertex (point2d(0, 1)); vertex_values.push_back (0); // Vertex 1. - g.add_vertex (point2d(0, 2)); vertex_values.push_back (0); // Vertex 2. - g.add_vertex (point2d(0, 3)); vertex_values.push_back (0); // Vertex 3. - - g.add_vertex (point2d(1, 0)); vertex_values.push_back (0); // Vertex 4. - g.add_vertex (point2d(1, 1)); vertex_values.push_back (0); // Vertex 5. - g.add_vertex (point2d(1, 2)); vertex_values.push_back (0); // Vertex 6. - g.add_vertex (point2d(1, 3)); vertex_values.push_back (0); // Vertex 7. - - // Edges. - std::vector<int> edge_values; - g.add_edge (0, 1); edge_values.push_back (0); - g.add_edge (1, 2); edge_values.push_back (10); - g.add_edge (2, 3); edge_values.push_back (5); - - g.add_edge (0, 4); edge_values.push_back (2); - g.add_edge (1, 5); edge_values.push_back (4); - g.add_edge (2, 6); edge_values.push_back (6); - g.add_edge (3, 7); edge_values.push_back (0); - - g.add_edge (4, 5); edge_values.push_back (3); - g.add_edge (5, 6); edge_values.push_back (5); - g.add_edge (6, 7); edge_values.push_back (2); - - // Line graph point set. - p_line_graph<point2d> plg(g); - - // Line graph image. - /* FIXME: We probably don't want to build line_graph_images by hand; - provide helpers and/or conversion functions. */ - typedef line_graph_image<point2d, int> ima_t; - ima_t ima(plg, vertex_values, edge_values); + util::graph g; + + // Sites associated to vertices. + typedef fun::i2v::array<point2d> fsite_t; + fsite_t sites(5); + sites(0) = point2d(0,0); // Point associated to vertex 0. + sites(1) = point2d(0,1); // Point associated to vertex 1. + sites(2) = point2d(0,2); // Point associated to vertex 2. + sites(3) = point2d(0,3); // Point associated to vertex 3. + sites(4) = point2d(1,0); // Point associated to vertex 4. + sites(5) = point2d(1,1); // Point associated to vertex 5. + sites(6) = point2d(1,2); // Point associated to vertex 6. + sites(7) = point2d(1,3); // Point associated to vertex 7. + + // Populate the graph with vertices. + for(unsigned i = 0; i < sites.size(); ++i) + g.add_vertex(); + + // Populate the graph with edges. + g.add_edge(0, 1); + g.add_edge(1, 2); + g.add_edge(2, 3); + + g.add_edge(0, 4); + g.add_edge(1, 5); + g.add_edge(2, 6); + g.add_edge(3, 7); + + g.add_edge(4, 5); + g.add_edge(5, 6); + g.add_edge(6, 7); + + typedef p_edges<util::graph, fsite_t> pe_t; + pe_t pe(g, sites); + + // Edge values. + typedef fun::i2v::array<int> edge_values_t; + edge_values_t edge_values(pe.nsites()); + + static const int values[] = { 0, 10, 5, 2, 4, 6, 0, 3, 5, 2 }; + for (unsigned i = 0; i < edge_values.size(); ++i) + edge_values(i) = values[i]; + + // Create line graph image. + mln_const_VAR(ima,(edge_values | pe)); + /*------------. | Iterators. | @@ -111,17 +123,16 @@ int main() std::cout << "ima (" << p << ") = " << ima(p) << std::endl; std::cout << std::endl; - typedef line_graph_elt_neighborhood<point2d> nbh_t; - nbh_t nbh; + typedef line_graph_elt_window<util::graph, fsite_t> win_t; + win_t win; + neighb<win_t> nbh(win); - typedef unsigned wst_val_t; - wst_val_t nbasins; - typedef line_graph_image<point2d, wst_val_t> wst_ima_t; - wst_ima_t wshed = morpho::meyer_wst(ima, nbh, nbasins); + unsigned nbasins; + mln_const_VAR(wshed, morpho::meyer_wst(ima, nbh, nbasins)); std::cout << "nbasins = " << nbasins << std::endl; // Manual iteration over the domain of WSHED. - mln_piter_(wst_ima_t) pw(wshed.domain()); + mln_piter_(wshed_t) pw(wshed.domain()); for_all (pw) std::cout << "wshed (" << pw << ") = " << wshed(pw) << std::endl; } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara