* tests/morpho/complex_image_morpho.cc: New. * tests/morpho/Makefile.am (check_PROGRAMS): Add complex_image_morpho. (complex_image_morpho_SOURCES): New. --- milena/ChangeLog | 9 ++ milena/tests/morpho/Makefile.am | 3 + milena/tests/morpho/complex_image_morpho.cc | 147 +++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 milena/tests/morpho/complex_image_morpho.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index f5e4b5e..22c65e2 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,14 @@ 2008-10-04 Roland Levillain <roland@lrde.epita.fr> + First tests of morphological filters on complex-based images. + + * tests/morpho/complex_image_morpho.cc: New. + * tests/morpho/Makefile.am (check_PROGRAMS): Add + complex_image_morpho. + (complex_image_morpho_SOURCES): New. + +2008-10-04 Roland Levillain <roland@lrde.epita.fr> + Add a centered window of lower-dimension adjacent complex faces. * mln/core/image/complex_lower_window_p.hh: New. diff --git a/milena/tests/morpho/Makefile.am b/milena/tests/morpho/Makefile.am index d47f5d4..747d55d 100644 --- a/milena/tests/morpho/Makefile.am +++ b/milena/tests/morpho/Makefile.am @@ -8,6 +8,7 @@ check_PROGRAMS = \ closing_height \ closing_volume \ combined \ + complex_image_morpho \ contrast \ dilation \ dilation_max_h \ @@ -60,6 +61,8 @@ 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 +complex_image_morpho_SOURCES = complex_image_morpho.cc + meyer_wst_SOURCES = meyer_wst.cc combined_SOURCES = combined.cc diff --git a/milena/tests/morpho/complex_image_morpho.cc b/milena/tests/morpho/complex_image_morpho.cc new file mode 100644 index 0000000..cbe874f --- /dev/null +++ b/milena/tests/morpho/complex_image_morpho.cc @@ -0,0 +1,147 @@ +// 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_morpho.cc +/// \brief Test of mln::complex_image with morphological filters. + +#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_lower_window_p.hh> +#include <mln/core/image/complex_window_piter.hh> + +#include <mln/debug/iota.hh> + +#include <mln/morpho/erosion.hh> +#include <mln/morpho/dilation.hh> + +/* FIXME: Factor common parts with + milena/tests/core/image/complex_image.cc */ + + +int main() +{ + using namespace mln; + + /*----------. + | Complex. | + `----------*/ + + /* A 2-d (simplicial) complex and its adjacency graph. + + v0 e3 v3 + o-----------o v0----e3----v3 + / \ ,-----. / / \ | / + / . \ \ t1/ / / \ t1 / + e0 / / \ e1\ / / e4 e0. ,e1Ž `e4 + / /t0 \ \ ' / / t0 \ / + / `-----' \ / / | \ / + o-----------o v1----e2----v2 + v1 e2 v2 + + v = vertex + e = edge + t = triangle + */ + + + const unsigned D = 2; + + topo::complex<D> c; + + // 0-faces (points). + topo::n_face<0, D> v0 = c.add_face(); + topo::n_face<0, D> v1 = c.add_face(); + topo::n_face<0, D> v2 = c.add_face(); + topo::n_face<0, D> v3 = c.add_face(); + + // 1-faces (segments). + topo::n_face<1, D> e0 = c.add_face(v0 + v1); + topo::n_face<1, D> e1 = c.add_face(v0 + v2); + topo::n_face<1, D> e2 = c.add_face(v1 + v2); + topo::n_face<1, D> e3 = c.add_face(v0 + v3); + topo::n_face<1, D> e4 = c.add_face(v2 + v3); + + // 2-faces (triangles). + topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2); + topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4); + + + /*-------------------------. + | Complex-based site set. | + `-------------------------*/ + + typedef point2d P; + p_complex<D, P> pc(c); + + + /*----------------------. + | Complex-based image. | + `----------------------*/ + + using mln::value::int_u8; + + // An image type built on a 2-complex with mln::int_u8 values on + // each face. + typedef complex_image<D, P, int_u8> ima_t; + ima_t ima(pc); + // Initialize values. + debug::iota(ima); + + // 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; + std::cout << std::endl; + + /*---------------------------------------------------. + | Morphological operations on complex-based images. | + `---------------------------------------------------*/ + + typedef complex_lower_window_p<D, P> win_t; + win_t win; + + ima_t ima_dil = morpho::dilation(ima, win); + // Manual iteration over the domain of IMA_DIL. + for_all (p) + std::cout << "ima_dil (" << p << ") = " << ima_dil(p) << std::endl; + std::cout << std::endl; + + ima_t ima_ero = morpho::erosion(ima, win); + // Manual iteration over the domain of IMA_ERO. + for_all (p) + std::cout << "ima_ero (" << p << ") = " << ima_ero(p) << std::endl; + + /* FIXME: Exercise elementary erosion/dilation (with neighborhoods) + when available. */ +} -- 1.6.0.1