
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Augment demo on neighborhood genericity. * mln/core/image/dmorph/transformed_image.hh (operator()): Fix precondition. Layout. * mln/make/neighb2d.hh: New. * mln/make/all.hh: Update. * demos/genericity/neighborhood: New directory. * demos/genericity/neighborhood.cc: Move... * demos/genericity/neighborhood/neighborhood.cc: ...here. Revamp. * demos/genericity/neighborhood/duality.cc: New. * demos/genericity/neighborhood/world.pbm: New. * demos/genericity/neighborhood/drawing.pbm: New. * demos/genericity/neighborhood/permissive.cc: New. demos/genericity/neighborhood/duality.cc | 66 +++++++++++++++ demos/genericity/neighborhood/neighborhood.cc | 110 ++++++++++++++------------ demos/genericity/neighborhood/permissive.cc | 70 ++++++++++++++++ mln/core/image/dmorph/transformed_image.hh | 18 ++-- mln/make/all.hh | 4 mln/make/neighb2d.hh | 70 ++++++++++++++++ 6 files changed, 280 insertions(+), 58 deletions(-) Index: mln/core/image/dmorph/transformed_image.hh --- mln/core/image/dmorph/transformed_image.hh (revision 4166) +++ mln/core/image/dmorph/transformed_image.hh (working copy) @@ -139,10 +139,6 @@ - template <typename I, typename F, typename J> - void init_(tag::image_t, transformed_image<I,F>& target, const J& model); - - # ifndef MLN_INCLUDE_ONLY @@ -153,12 +149,18 @@ void init_(tag::image_t, transformed_image<I,F>& target, const J& model) { I ima; - init_(tag::image, ima, model); + init_(tag::image, ima, exact(model)); F f; - init_(tag::function, f, model); + init_(tag::function, f, exact(model)); target.init_(ima, f); } + template <typename I, typename F> + void init_(tag::function_t, F& f, const transformed_image<I,F>& model) + { + f = model.domain().function(); + } + // internal::data< transformed_image<I,F> > @@ -216,7 +218,7 @@ { mln_precondition(this->delegatee_() != 0); mln_precondition(exact(this)->has(p)); - mln_precondition(this->delegatee_()->has(p)); + mln_precondition(this->delegatee_()->has(this->data_->f_(p))); return this->delegatee_()->operator()(this->data_->f_(p)); } @@ -227,7 +229,7 @@ { mln_precondition(this->delegatee_() != 0); mln_precondition(exact(this)->has(p)); - mln_precondition(this->delegatee_()->has(p)); + mln_precondition(this->delegatee_()->has(this->data_->f_(p))); return this->delegatee_()->operator()(this->data_->f_(p)); } Index: mln/make/neighb2d.hh --- mln/make/neighb2d.hh (revision 0) +++ mln/make/neighb2d.hh (revision 0) @@ -0,0 +1,70 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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. + +#ifndef MLN_MAKE_NEIGHB2D_HH +# define MLN_MAKE_NEIGHB2D_HH + +/// \file +/// +/// \brief Routine to create a double neighborhood. +/// +/// \todo Add overload with 'when_*' being Neighborhood<N>... + +# include <mln/core/alias/neighb2d.hh> + + +namespace mln +{ + + namespace make + { + + template <unsigned S> + mln::neighb2d + neighb2d(bool const (&vals) [S]); + + +# ifndef MLN_INCLUDE_ONLY + + template <unsigned S> + inline + mln::neighb2d + neighb2d(bool const (&vals) [S]) + { + enum { h = mlc_sqrt_int(S) / 2 }; + mlc_bool((2 * h + 1) * (2 * h + 1) == S)::check(); + mln::neighb2d nbh; + convert::from_to(vals, nbh); + return nbh; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + + +#endif // ! MLN_MAKE_NEIGHB2D_HH Index: mln/make/all.hh --- mln/make/all.hh (revision 4166) +++ mln/make/all.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -49,6 +50,7 @@ # include <mln/make/image2d.hh> # include <mln/make/image3d.hh> # include <mln/make/mat.hh> +# include <mln/make/neighb2d.hh> # include <mln/make/pix.hh> # include <mln/make/pixel.hh> # include <mln/make/point2d_h.hh> Index: demos/genericity/neighborhood/duality.cc --- demos/genericity/neighborhood/duality.cc (revision 0) +++ demos/genericity/neighborhood/duality.cc (revision 0) @@ -0,0 +1,66 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 demos/genericity/neighborhood/duality.cc +/// +/// Demo on dual neighborhoods. + +#include <mln/core/image/image2d.hh> +#include <mln/io/pbm/load.hh> +#include <mln/labeling/colorize.hh> +#include <mln/labeling/flat_zones.hh> +#include <mln/value/rgb8.hh> +#include <mln/io/ppm/save.hh> + +#include <mln/core/alias/neighb2d.hh> +#include <mln/make/dual_neighb.hh> + + + +template <typename N> +void labelize(const mln::image2d<bool>& pic, + const N& nbh, + const std::string& filename) +{ + using namespace mln; + using value::rgb8; + unsigned n; + image2d<unsigned> lab = labeling::flat_zones(pic, nbh, n); + image2d<rgb8> out = labeling::colorize(rgb8(), lab, n); + io::ppm::save(out, filename); +} + + + +int main() +{ + using namespace mln; + + image2d<bool> pic = io::pbm::load("drawing.pbm"); + + labelize(pic, make::dual_neighb(pic, c4(), c8()), "c4_c8.ppm"); + labelize(pic, make::dual_neighb(pic, c8(), c4()), "c8_c4.ppm"); + labelize(pic, c6_2d(), "c6_c6.ppm"); +} Index: demos/genericity/neighborhood/world.pbm Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: demos/genericity/neighborhood/world.pbm ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: demos/genericity/neighborhood/drawing.pbm Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: demos/genericity/neighborhood/drawing.pbm ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: demos/genericity/neighborhood/permissive.cc --- demos/genericity/neighborhood/permissive.cc (revision 0) +++ demos/genericity/neighborhood/permissive.cc (revision 0) @@ -0,0 +1,70 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 demos/genericity/neighborhood/permissive.cc +/// +/// Demo on user-defined simple neighborhood. + +#include <mln/core/image/image2d.hh> +#include <mln/io/pbm/load.hh> + +#include <mln/make/neighb2d.hh> +#include <mln/labeling/blobs.hh> + +#include <mln/io/ppm/save.hh> +#include <mln/labeling/colorize.hh> +#include <mln/value/rgb8.hh> + +#include <mln/fun/p2p/fold.hh> +#include <mln/core/image/dmorph/transformed_image.hh> + + + +int main() +{ + using namespace mln; + + image2d<bool> world = io::pbm::load("world.pbm"); + + bool large[] = { 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 }; + neighb2d nbh = make::neighb2d(large); + + unsigned n; + image2d<unsigned> labeled = labeling::blobs(world, nbh, n); + + io::ppm::save(labeling::colorize(value::rgb8(), labeled, n), + "world.ppm"); + + + fun::p2p::fold<point2d,0,1> f(world.domain()); + labeled = labeling::blobs(transform_domain(world, f), nbh, n).unmorph_(); + + io::ppm::save(labeling::colorize(value::rgb8(), labeled, n), + "world_bis.ppm"); +} Index: demos/genericity/neighborhood/neighborhood.cc --- demos/genericity/neighborhood/neighborhood.cc (revision 0) +++ demos/genericity/neighborhood/neighborhood.cc (working copy) @@ -1,52 +1,46 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // -// This file is part of the Milena 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 file is part of Olena. // -// This library is distributed in the hope that it will be useful, +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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. +// along with Olena. If not, see <http://www.gnu.org/licenses/>. // // As a special exception, you may use this file as part of a free -// software library without restriction. Specifically, if other files +// software project 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, 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 demos/genericity/neighborhood.cc +/// \file demos/genericity/neighborhood/neighborhood.cc /// -/// Test on mln::labeling::blobs. +/// Demo on using or defining neighborhoods. #include <mln/core/image/image2d.hh> -#include <mln/io/pbm/load.hh> #include <mln/labeling/blobs.hh> #include <mln/labeling/colorize.hh> -#include <mln/labeling/flat_zones.hh> #include <mln/value/rgb8.hh> #include <mln/io/ppm/save.hh> -#include <mln/core/alias/neighb2d.hh> -#include <mln/make/dual_neighb.hh> +#include <mln/io/pbm/load.hh> +#include <mln/make/neighb2d.hh> #include <mln/make/double_neighb2d.hh> -#include <mln/debug/println.hh> -#include "../../tests/data.hh" template <typename N> -void run(const mln::image2d<bool>& pic, +void labelize(const mln::image2d<bool>& pic, const N& nbh, const std::string& filename) { @@ -59,41 +53,59 @@ } +bool chess(const mln::point2d& p) +{ + return (p.row() + p.col()) % 2 == 0; +} + +bool top_right(const mln::point2d& p) +{ + return p.col() >= p.row(); +} + + int main() { using namespace mln; - image2d<bool> pic = io::pbm::load(MLN_IMG_DIR "/small.pbm"); + image2d<bool> pic = io::pbm::load("drawing.pbm"); - run(pic, c4(), "c4.ppm"); - run(pic, c8(), "c8.ppm"); - run(pic, c6_2d(), "c6.ppm"); + // Classical 2D neighborhoods. - { - bool vert[] = { 0, 1, 0, - 0, 0, 0, - 0, 1, 0 }; + labelize(pic, c4(), "c4.ppm"); + labelize(pic, c8(), "c8.ppm"); - bool hori[] = { 0, 0, 0, + + // A user-defined simple neighborhood. + + bool horiz[] = { 0, 0, 0, 1, 0, 1, 0, 0, 0 }; - run(pic, - make::double_neighb2d(fun::p2b::chess(), vert, hori), - "cmy.ppm"); - } + labelize(pic, make::neighb2d(horiz), "c2.ppm"); - { - using value::rgb8; - unsigned n; - image2d<unsigned> lab; - lab = labeling::flat_zones(pic, - make::dual_neighb(pic, - c4(), // object - c8()), // background - n); - image2d<rgb8> out = labeling::colorize(rgb8(), lab, n); - io::ppm::save(out, "cdual48.ppm"); - } + // Another user-defined simple neighborhood. + + bool tilt[] = { 1, 1, 0, + 0, 0, 0, + 0, 1, 1 }; + labelize(pic, make::neighb2d(tilt), "cZ.ppm"); + + + // A user-defined double-neighborhood. + + bool nbh1[] = { 1, 1, 0, + 1, 0, 1, + 0, 1, 1 }; + + bool nbh2[] = { 0, 1, 1, + 1, 0, 1, + 1, 1, 0 }; + labelize(pic, make::double_neighb2d(chess, nbh1, nbh2), "c6.ppm"); + + + // Another user-defined double-neighborhood. + + labelize(pic, make::double_neighb2d(top_right, nbh1, nbh2), "cX.ppm"); } Property changes on: demos/genericity/neighborhood/neighborhood.cc ___________________________________________________________________ Added: svn:mergeinfo