
* tests/core/image/graph_image_wst.cc: Move test... * tests/morpho/graph_image_wst.cc: ...here. Catch up with interfaces of cleanup-2008. Turn this test into an actual WST segmentation of a graph image. * tests/core/image/Makefile.am (check_PROGRAM): Remove graph_image_wst. (graph_image_wst_SOURCES): Move... * tests/morpho/Makefile.am: ...here. (check_PROGRAM): Add graph_image_wst. --- milena/ChangeLog | 14 +++ milena/tests/core/image/Makefile.am | 5 - milena/tests/core/image/graph_image_wst.cc | 149 ---------------------------- milena/tests/morpho/Makefile.am | 3 + milena/tests/morpho/graph_image_wst.cc | 120 ++++++++++++++++++++++ 5 files changed, 137 insertions(+), 154 deletions(-) delete mode 100644 milena/tests/core/image/graph_image_wst.cc create mode 100644 milena/tests/morpho/graph_image_wst.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 193a46d..f0781e3 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,19 @@ 2008-09-23 Roland Levillain <roland@lrde.epita.fr> + Fix test graph_image_wst. + + * tests/core/image/graph_image_wst.cc: Move test... + * tests/morpho/graph_image_wst.cc: ...here. + Catch up with interfaces of cleanup-2008. + Turn this test into an actual WST segmentation of a graph image. + * tests/core/image/Makefile.am (check_PROGRAM): Remove + graph_image_wst. + (graph_image_wst_SOURCES): Move... + * tests/morpho/Makefile.am: ...here. + (check_PROGRAM): Add graph_image_wst. + +2008-09-23 Roland Levillain <roland@lrde.epita.fr> + Fix more morphological tests on graph-based images. * tests/morpho/Makefile.am (check_PROGRAMS): Re-enable diff --git a/milena/tests/core/image/Makefile.am b/milena/tests/core/image/Makefile.am index dc247cc..27435a1 100644 --- a/milena/tests/core/image/Makefile.am +++ b/milena/tests/core/image/Makefile.am @@ -10,7 +10,6 @@ check_PROGRAMS = \ flat_image \ ## hexa \ graph_image \ -## graph_image_wst \ image1d \ image2d \ ## image2d_h \ @@ -36,10 +35,6 @@ cast_image_SOURCES = cast_image.cc complex_image_SOURCES = complex_image.cc decorated_image_SOURCES = decorated_image.cc graph_image_SOURCES = graph_image.cc -### FIXME: graph_image_wst is almost a clone of graph_image: move it -### into tests/morpho and turn it into a real test on the WST (see -### line_graph_image_wst). -##graph_image_wst_SOURCES = graph_image_wst.cc flat_image_SOURCES = flat_image.cc ##hexa_SOURCES = hexa.cc image1d_SOURCES = image1d.cc diff --git a/milena/tests/core/image/graph_image_wst.cc b/milena/tests/core/image/graph_image_wst.cc deleted file mode 100644 index 8f2acc3..0000000 --- a/milena/tests/core/image/graph_image_wst.cc +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of the Olena Library. This library is free -// software; you can redistribute it and/or modify it under the terms -// of the GNU General Public License version 2 as published by the -// Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this library; see the file COPYING. If not, write to -// the Free Software Foundation, 51 Franklin Street, Fifth Floor, -// Boston, MA 02111-1307, USA. -// -// As a special exception, you may use this file as part of a free -// software library without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to -// produce an executable, this file does not by itself cause the -// resulting executable to be covered by the GNU General Public -// License. This exception does not however invalidate any other -// reasons why the executable file might be covered by the GNU General -// Public License. - -/// \file tests/core/image/graph_image_wst.cc -/// \brief Tests on the Watershed Transform on a mln::graph_image. - -#include <vector> - -#include <mln/core/alias/point2d.hh> -#include <mln/core/image/graph_image.hh> -#include <mln/core/image/graph_elt_window.hh> -#include <mln/core/image/graph_window_piter.hh> - -#include <mln/morpho/dilation.hh> - -#include <mln/draw/graph.hh> -#include <mln/debug/iota.hh> -#include <mln/debug/println.hh> - - -int main() -{ - using namespace mln; - - /*--------. - | Graph. | - `--------*/ - - // Points associated to nodes. - std::vector<point2d> points; - points.push_back(point2d(0,0)); // Point associated to node 0. - points.push_back(point2d(2,2)); // Point associated to node 1. - points.push_back(point2d(0,4)); // Point associated to node 2. - points.push_back(point2d(4,3)); // Point associated to node 3. - points.push_back(point2d(4,4)); // Point associated to node 4. - - // Edges. - util::graph<point2d> g; - // Populate the graph with nodes. - for (unsigned i = 0; i < points.size(); ++i) - g.add_node (points[i]); - // Populate the graph with edges. - g.add_edge(0, 1); - g.add_edge(1, 2); - g.add_edge(1, 3); - g.add_edge(3, 4); - g.add_edge(4, 2); - - /*-------. - | Graph. | - `-------*/ - - p_graph<point2d> pg(g); - - /*-------------. - | Graph image. | - `-------------*/ - - // Values ("empty" vector). - std::vector<int> values(5); - // Graph image. - typedef graph_image<point2d, int> ima_t; - ima_t ima(pg, values); - // Initialize values. - debug::iota(ima); - // Print the image. - /* FIXME: Unfortunately, displaying graph images is not easy right - now (2008-02-05). We could use - - debug::println(ima); - - but there's not specialization working for graph_image; the one - selected by the compiler is based on a 2-D bbox, and expects the - 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 nodes and edges of the - graph. - - The current solution is a mix between draw::graph and hand-made - iterations. */ - image2d<int> ima_rep(ima.bbox()); - // We use the value 9 in draw::graph instead of the default (which is - // 1) to represent edges to distinguish it from nodes holding a - // value of 1. - draw::graph (ima_rep, ima, 9); - debug::println (ima_rep); - - - /*------------. - | Iterators. | - `------------*/ - - // Manual iteration over the domain of IMA. - mln_piter_(ima_t) p(ima.domain()); - for_all (p) - std::cout << "ima (" << p << ") = " << ima(p) << std::endl; - - // Manual iterations over the neighborhoods of each point site of IMA. - typedef graph_elt_window<point2d> win_t; - win_t win; - mln_qiter_(win_t) q(win, p); - for_all (p) - { - std::cout << "neighbors of " << p << " (" << ima(p) << "), " - << "including the site itself:" << std::endl; - for_all (q) - std::cout << " " << q << " (level = " << ima(q) << ")" << std::endl; - } - std::cout << std::endl; - - /*-------------------------. - | Processing graph images. | - `-------------------------*/ - - graph_image<point2d, int> ima_dil = morpho::dilation(ima, win); - draw::graph(ima_rep, ima_dil, 9); - debug::println(ima_rep); - - graph_image<point2d, int> ima_ero = morpho::erosion(ima, win); - draw::graph(ima_rep, ima_ero, 9); - debug::println(ima_rep); -} diff --git a/milena/tests/morpho/Makefile.am b/milena/tests/morpho/Makefile.am index 48e3a82..d47f5d4 100644 --- a/milena/tests/morpho/Makefile.am +++ b/milena/tests/morpho/Makefile.am @@ -16,6 +16,7 @@ check_PROGRAMS = \ gradient \ gradient_elementary \ graph_image_morpho \ + graph_image_wst \ hit_or_miss \ laplacian \ lena_line_graph_image_wst1 \ @@ -54,9 +55,11 @@ laplacian_SOURCES = laplacian.cc thinning_SOURCES = thinning.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 + meyer_wst_SOURCES = meyer_wst.cc combined_SOURCES = combined.cc diff --git a/milena/tests/morpho/graph_image_wst.cc b/milena/tests/morpho/graph_image_wst.cc new file mode 100644 index 0000000..41dcd5e --- /dev/null +++ b/milena/tests/morpho/graph_image_wst.cc @@ -0,0 +1,120 @@ +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/// \file tests/morpho/graph_image_wst.cc +/// \brief Tests on the Watershed Transform on a mln::graph_image. + +#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> + +#include <mln/morpho/meyer_wst.hh> + + +int main() +{ + using namespace mln; + + /*--------. + | Graph. | + `--------*/ + + /* The graph is as follows: + + 0 1 2 3 4 + .----------- + | + 0 | 0 2 + 1 | \ / | + 2 | 1 | + 3 | \ | + 4 | 3-0 + + */ + + // 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; + // Populate the graph with vertices. + for (unsigned i = 0; i < points.size(); ++i) + g.add_vertex (points[i]); + // Populate the graph with edges. + g.add_edge(0, 1); + g.add_edge(1, 2); + g.add_edge(1, 3); + g.add_edge(3, 4); + g.add_edge(4, 2); + + /*-------. + | Graph. | + `-------*/ + + p_graph<point2d> pg(g); + + /*-------------. + | 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); + + /*------. + | WST. | + `------*/ + + typedef graph_elt_neighborhood<point2d> nbh_t; + nbh_t nbh; + + 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); + std::cout << "nbasins = " << nbasins << std::endl; + + // Manual iteration over the domain of WSHED. + mln_piter_(wst_ima_t) pw(wshed.domain()); + for_all (pw) + std::cout << "wshed (" << pw << ") = " << wshed(pw) << std::endl; +} -- 1.6.0.1
participants (1)
-
Roland Levillain