2681: Test Meyer's WST on complex-based images.

* tests/morpho/complex_image_wst.cc: New. * tests/morpho/Makefile.am (check_PROGRAMS): Add complex_image_wst. (complex_image_wst_SOURCES): New. --- milena/ChangeLog | 8 + milena/tests/morpho/Makefile.am | 2 + milena/tests/morpho/complex_image_wst.cc | 207 ++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+), 0 deletions(-) create mode 100644 milena/tests/morpho/complex_image_wst.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 2da6062..cd5b784 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,13 @@ 2008-10-24 Roland Levillain <roland@lrde.epita.fr> + Test Meyer's WST on complex-based images. + + * tests/morpho/complex_image_wst.cc: New. + * tests/morpho/Makefile.am (check_PROGRAMS): Add complex_image_wst. + (complex_image_wst_SOURCES): New. + +2008-10-24 Roland Levillain <roland@lrde.epita.fr> + Fix a bug in iterators on n-faces. * mln/topo/n_face_iter.hh diff --git a/milena/tests/morpho/Makefile.am b/milena/tests/morpho/Makefile.am index 747d55d..b2f060a 100644 --- a/milena/tests/morpho/Makefile.am +++ b/milena/tests/morpho/Makefile.am @@ -9,6 +9,7 @@ check_PROGRAMS = \ closing_volume \ combined \ complex_image_morpho \ + complex_image_wst \ contrast \ dilation \ dilation_max_h \ @@ -62,6 +63,7 @@ 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 meyer_wst_SOURCES = meyer_wst.cc diff --git a/milena/tests/morpho/complex_image_wst.cc b/milena/tests/morpho/complex_image_wst.cc new file mode 100644 index 0000000..88e5bc9 --- /dev/null +++ b/milena/tests/morpho/complex_image_wst.cc @@ -0,0 +1,207 @@ +// Copyright (C) 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/complex_image_swt.cc +/// \brief Testing Meyer's Watershed Transform on mln::complex_image. + +#include <iostream> + +#include <mln/value/int_u8.hh> +#include <mln/core/alias/point2d.hh> + +#include <mln/core/site_set/p_faces.hh> +#include <mln/core/image/complex_image.hh> + +// FIXME: Include these elsewhere? (In complex_image.hh?) +#include <mln/core/image/complex_neighborhoods.hh> +#include <mln/core/image/complex_neighborhood_piter.hh> + +#include <mln/debug/iota.hh> +#include <mln/level/fill.hh> +#include <mln/norm/l2.hh> + +#include <mln/morpho/closing_area.hh> +#include <mln/morpho/meyer_wst.hh> + + +int main() +{ + using namespace mln; + using mln::value::int_u8; + + /*----------------------------------------. + | Complex + complex geometry (location). | + `----------------------------------------*/ + + /* A (simplicial) 1-complex and its adjacency graph. + + c 0 1 2 3 + r .------------------------ + | v0 e3 v3 + 0 | o-----------o v0----e3----v3 + | / \ / / \ / + | / \ / / \ / + 1 | e0 / e1 / e4 e0 e1 e4 + | / \ / / \ / + | / \ / / \ / + 2 | o-----------o v1----e2----v2 + | v1 e2 v2 + + v = vertex + e = edge + */ + + + const unsigned D = 1; + + topo::complex<D> c; + + typedef point2d P; + typedef geom::complex_geometry<D, P> G; + G geom; + + // Convenience typedefs. + typedef topo::n_face<0, D> vertex; + typedef topo::n_face<1, D> edge; + + // 0-faces (vertices). + vertex v0 = c.add_face(); geom.add_location(point2d(0,1)); + vertex v1 = c.add_face(); geom.add_location(point2d(2,0)); + vertex v2 = c.add_face(); geom.add_location(point2d(2,2)); + vertex v3 = c.add_face(); geom.add_location(point2d(0,3)); + + // 1-faces (edges). + edge e0 = c.add_face(-v1 + v0); + edge e1 = c.add_face(-v2 + v0); + edge e2 = c.add_face(-v2 + v1); + edge e3 = c.add_face(-v0 + v3); + edge e4 = c.add_face(-v3 + v2); + + /*---------------------. + | Complex-based pset. | + `---------------------*/ + + p_complex<D, G> pc(c, geom); + + /*----------------------. + | Complex-based image. | + `----------------------*/ + + // An image type built on a 1-complex with unsigned values on each + // face (both vertices and edges). + typedef complex_image<D, G, unsigned> dist_ima_t; + + // Create and initialize an image based on PC. + dist_ima_t dist_ima(pc); + level::fill(dist_ima, 0u); + + /*--------------------------------. + | Complex-based image iterators. | + `--------------------------------*/ + + // For each edge (1-face), compute the distance between the two + // adjacent vertices (0-faces). + p_n_faces_fwd_piter<D, G> e(dist_ima.domain(), 1); + typedef complex_lower_neighborhood<D, G> v_nbh_t; + v_nbh_t v_nbh; + mln_niter_(v_nbh_t) v(v_nbh, e); + for_all(e) + { + v.start(); + point2d p1 = v.to_site().front(); + v.next(); + point2d p2 = v.to_site().front(); + v.next(); + mln_invariant(!v.is_valid()); + + dist_ima(e) = 10 * norm::l2_distance(p1.to_vec(), p2.to_vec()); + } + // Initialize 0-faces to a dummy value, to prevent the watershed from + // finding minima on 0-faces. + p_n_faces_fwd_piter<D, G> v_(dist_ima.domain(), 0); + for_all(v_) + dist_ima(v_) = mln_max(mln_value_(dist_ima_t)); + + // For all edges, iterate on adjacent edges (i.e., on edges sharing + // an adjacent vertex). + typedef complex_lower_dim_connected_n_face_neighborhood<D, G> nbh_t; + nbh_t nbh; + // Neighbor edge. + mln_niter_(nbh_t) ne(nbh, e); + for_all(e) + { + std::cout << "dist_ima(" << e << ") = " << dist_ima(e) + << " -- adjacent edges :" << std::endl; + for_all(ne) + std::cout << " " << ne << std::endl; + } + + /*-----------------. + | Simplification. | + `-----------------*/ + + // Currently, does nothing (lambda = 1). + dist_ima_t closed_dist_ima (dist_ima.domain()); + morpho::closing_area(dist_ima, nbh, 1, closed_dist_ima); + + /*------. + | WST. | + `------*/ + + // Perform a Watershed Transform. + typedef unsigned wst_val_t; + wst_val_t nbasins; + typedef complex_image<D, G, wst_val_t> wst_ima_t; + wst_ima_t wshed = morpho::meyer_wst(closed_dist_ima, nbh, nbasins); + /* Note that since the image is based not only on the 1-faces but + also on the 0-faces of the complex, and given the above + neighborhood, the domain seen by the WST is not connected! It is + actually composed of five components : + + - a component containing all the 1-faces (egdes) which are all + connected through + mln::complex_lower_dim_connected_n_face_neighborhood; + + - four (singleton) components corresponding to the 0-faces + (vertices), connected to no other part of the complex according to + mln::complex_lower_dim_connected_n_face_neighborhood. + + Since the component made of the edges contains two local minima, + the number of basins is equal to 6: + + 2 minima for the edges' component + + 4 * 1 minima for the vertices's components + -------------------------------------------- + 6 basins. + + Hence the result. + + + We definitely need a complex_image that can accept a subset of a + complex as domain (or at least a p_face<N, D, P>. */ + std::cout << "nbasins = " << nbasins << std::endl; +} -- 1.5.6.5
participants (1)
-
Roland Levillain