cleanup-2008 2828: Add a couple of geodesic transforms.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add a couple of geodesic transforms. * mln/transform/influence_zone_geodesic.hh: New. * mln/transform/all.hh: Update. * tests/transform/influence_zone_geodesic.cc: New. * mln/transform/distance_geodesic.hh: New. * tests/transform/distance_geodesic.cc: New. mln/transform/all.hh | 13 +- mln/transform/distance_geodesic.hh | 153 +++++++++++++++++++++++++++ mln/transform/influence_zone_geodesic.hh | 160 +++++++++++++++++++++++++++++ tests/transform/distance_geodesic.cc | 52 +++++++++ tests/transform/influence_zone_geodesic.cc | 58 ++++++++++ 5 files changed, 430 insertions(+), 6 deletions(-) Index: tests/transform/distance_geodesic.cc --- tests/transform/distance_geodesic.cc (revision 0) +++ tests/transform/distance_geodesic.cc (revision 0) @@ -0,0 +1,52 @@ +// 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/transform/distance_geodesic.cc +/// +/// Test on mln::transform::distance_geodesic. + +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/level/fill.hh> +#include <mln/debug/println.hh> + +#include <mln/transform/distance_geodesic.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d<bool> input(9, 9); + level::fill(input, false); + input.at(4, 4) = true; + + image2d<int_u8> output = transform::distance_geodesic(input, c4(), int_u8(4)); + debug::println(output); +} Index: tests/transform/influence_zone_geodesic.cc --- tests/transform/influence_zone_geodesic.cc (revision 0) +++ tests/transform/influence_zone_geodesic.cc (revision 0) @@ -0,0 +1,58 @@ +// 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/transform/influence_zone_geodesic.cc +/// +/// Test on mln::transform::influence_zone_geodesic. + +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/make/image2d.hh> +#include <mln/debug/println.hh> + +#include <mln/transform/influence_zone_geodesic.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + int_u8 vals[] = + { 1, 1, 0, 0, 0, 0, 3, + 1, 1, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 2, 2, 0, + 0, 0, 0, 0, 0, 0, 0 }; + image2d<int_u8> input = make::image2d(vals); + + image2d<int_u8> output = transform::influence_zone_geodesic(input, c4(), int_u8(1)); + debug::println(output); +} Index: mln/transform/influence_zone_geodesic.hh --- mln/transform/influence_zone_geodesic.hh (revision 0) +++ mln/transform/influence_zone_geodesic.hh (revision 0) @@ -0,0 +1,160 @@ +// 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. + +#ifndef MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH +# define MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH + +/// \file mln/transform/influence_zone_geodesic.hh +/// +/// Discrete geodesic distance transform. + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/neighborhood.hh> +# include <mln/core/site_set/p_queue_fast.hh> +# include <mln/core/routine/clone.hh> +# include <mln/level/fill.hh> + +# include <mln/debug/println.hh> + + +namespace mln +{ + + namespace transform + { + + /// Discrete geodesic distance transform. + template <typename I, typename N, typename D> + mln_concrete(I) + influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + namespace generic + { + + template <typename I, typename N, typename D> + mln_concrete(I) + influence_zone_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_, + D max) + { + trace::entering("transform::impl::generic::influence_zone_geodesic"); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + + mln_precondition(input.has_data()); + + mln_ch_value(I, D) dmap; // Distance map is aux data. + initialize(dmap, input); + + typedef mln_site(I) P; + p_queue_fast<P> q; + + mln_concrete(I) output = clone(input); + + // Initialization. + { + level::fill(dmap, max); + mln_piter(I) p(input.domain()); + mln_niter(N) n(nbh, p); + for_all(p) + if (input(p) != 0) // p in a component + { + dmap(p) = 0; + for_all(n) + if (input.domain().has(n) && input(n) == 0) // n in background + { + q.push(p); + break; + } + } + } + + // Propagation. + { + P p; + mln_niter(N) n(nbh, p); + while (! q.is_empty()) + { + p = q.pop_front(); + if (dmap(p) == max) + { + // Saturation so stop. + q.clear(); + break; + } + for_all(n) + if (input.domain().has(n) && dmap(n) == max) + { + dmap(n) = dmap(p) + 1; + output(n) = output(p); + q.push(n); + } + } + } + + trace::exiting("transform::impl::generic::influence_zone_geodesic"); + return output; + } + + } // end of namespace mln::transform::impl::generic + + } // end of namespace mln::transform::impl + + + // Facade. + + template <typename I, typename N, typename D> + inline + mln_concrete(I) + influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, + D distance_max) + { + trace::entering("transform::influence_zone_geodesic"); + + // FIXME: tests. + + mln_concrete(I) output; + output = impl::generic::influence_zone_geodesic(input, nbh, distance_max); + + trace::exiting("transform::influence_zone_geodesic"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::transform + +} // end of namespace mln + + +#endif // ! MLN_TRANSFORM_DISTANCE_HH Index: mln/transform/all.hh --- mln/transform/all.hh (revision 2827) +++ mln/transform/all.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// 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 @@ -28,22 +28,23 @@ #ifndef MLN_TRANSFORM_ALL_HH # define MLN_TRANSFORM_ALL_HH -/*! \file mln/transform/all.hh - * - * \brief File that includes all "point-wise" expression tools. - */ +/// \file mln/transform/all.hh +/// +/// File that includes all transforms. namespace mln { - /// Namespace of "point-wise" expression tools. + /// Namespace of transforms. namespace transform {} } // end of namespace mln # include <mln/transform/distance.hh> +# include <mln/transform/distance_geodesic.hh> +# include <mln/transform/influence_zone_geodesic.hh> #endif // ! MLN_TRANSFORM_ALL_HH Index: mln/transform/distance_geodesic.hh --- mln/transform/distance_geodesic.hh (revision 0) +++ mln/transform/distance_geodesic.hh (revision 0) @@ -0,0 +1,153 @@ +// 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. + +#ifndef MLN_TRANSFORM_DISTANCE_GEODESIC_HH +# define MLN_TRANSFORM_DISTANCE_GEODESIC_HH + +/// \file mln/transform/distance_geodesic.hh +/// +/// Discrete geodesic distance transform. + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/neighborhood.hh> +# include <mln/core/site_set/p_queue_fast.hh> +# include <mln/level/fill.hh> + + + +namespace mln +{ + + namespace transform + { + + /// Discrete geodesic distance transform. + template <typename I, typename N, typename D> + mln_ch_value(I, D) + distance_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + namespace generic + { + + template <typename I, typename N, typename D> + mln_ch_value(I, D) + distance_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_, D max) + { + trace::entering("transform::impl::generic::distance_geodesic"); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + + mln_precondition(input.has_data()); + + mln_ch_value(I, D) output; + initialize(output, input); + + typedef mln_site(I) P; + p_queue_fast<P> q; + + // Initialization. + { + level::fill(output, max); + mln_piter(I) p(input.domain()); + mln_niter(N) n(nbh, p); + for_all(p) + if (input(p) == true) // p in object + { + output(p) = 0; + for_all(n) + if (input.domain().has(n) && input(n) == false) // n in background + { + q.push(p); + break; + } + } + } + + // Propagation. + { + P p; + mln_niter(N) n(nbh, p); + while (! q.is_empty()) + { + p = q.pop_front(); + for_all(n) + if (input.domain().has(n) && output(n) == max) + { + output(n) = output(p) + 1; + if (output(n) == max) + { + // Saturation so stop. + q.clear(); + break; + } + q.push(n); + } + } + } + + trace::exiting("transform::impl::generic::distance_geodesic"); + return output; + } + + } // end of namespace mln::transform::impl::generic + + } // end of namespace mln::transform::impl + + + // Facade. + + template <typename I, typename N, typename D> + inline + mln_ch_value(I, D) + distance_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max) + { + trace::entering("transform::distance_geodesic"); + + // FIXME: tests. + + mln_ch_value(I, D) output; + output = impl::generic::distance_geodesic(input, nbh, max); + + trace::exiting("transform::distance_geodesic"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::transform + +} // end of namespace mln + + +#endif // ! MLN_TRANSFORM_DISTANCE_HH
participants (1)
-
Thierry Geraud