3050: Add Autarkical Leveling, move files ot trunk.

https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox Index: ChangeLog from Alexandre Abraham <abraham@lrde.epita.fr> Add Autarkical Leveling, move files ot trunk. * abraham/tests/morpho/levelings.cc: New Test for autorkical leveling. * abraham/tests/morpho/red_erosion.cc: New Make red erosion with fun_image (not working yet). * abraham/tests/morpho/red_erosion3.cc: New Make red erosion with mixin. * abraham/tests/fun/meta/red.cc: Update. * abraham/tests/core/image/fun_image_const.cc: New. * abraham/tests/core/image/fun_image_norm.cc: New. * abraham/tests/core/image/fun_image_v2v.cc: New. * abraham/tests/core/image/fun_image_v2w2v.cc: New. * abraham/tests/value/mixin.cc: Update. * abraham/mln/morpho/autarkical_leveling.hh: New Autarkical leveling (see Golima). * abraham/mln/morpho/topo_wst.hh: Update. * abraham/mln/morpho/vector_median.hh: New Morphological operator needed for autarkical leveliing. * abraham/mln/core/image/thru.hh: Move to trunk under the name fun_image.hh. * abraham/mln/core/image/violent_cast_image.hh: Move to trunk. * abraham/mln/core/concept/function.hh: Move to trunk. * abraham/mln/fun/v2w2v: Move to trunk. * abraham/mln/fun/v2w2v/cos.hh: Move to trunk. * abraham/mln/fun/meta: Move to trunk. * abraham/mln/fun/meta/hue.hh: Move to trunk. * abraham/mln/fun/meta/inty.hh: Move to trunk. * abraham/mln/fun/meta/sat.hh: Move to trunk. * abraham/mln/fun/meta/to_enc.hh: Move to trunk. * abraham/mln/fun/meta/red.hh: Move to trunk. * abraham/mln/fun/v2w_w2v: Move to trunk. * abraham/mln/fun/v2w_w2v/norm.hh: Move to trunk. * abraham/mln/value/mixin.hh: Move to trunk. * abraham/mln/value/op_less.hh: Move to trunk. mln/core/concept/function.hh | 526 ----------------------------------- mln/core/image/thru.hh | 193 ------------ mln/core/image/violent_cast_image.hh | 180 ----------- mln/fun/meta/hue.hh | 64 ---- mln/fun/meta/inty.hh | 65 ---- mln/fun/meta/red.hh | 44 -- mln/fun/meta/sat.hh | 64 ---- mln/fun/meta/to_enc.hh | 57 --- mln/fun/v2w2v/cos.hh | 95 ------ mln/fun/v2w_w2v/norm.hh | 155 ---------- mln/morpho/autarkical_leveling.hh | 290 +++++++++++++++++++ mln/morpho/topo_wst.hh | 24 - mln/morpho/vector_median.hh | 129 ++++++++ mln/value/mixin.hh | 156 ---------- mln/value/op_less.hh | 46 --- tests/core/image/fun_image_const.cc | 64 ++++ tests/core/image/fun_image_norm.cc | 63 ++++ tests/core/image/fun_image_v2v.cc | 56 +++ tests/core/image/fun_image_v2w2v.cc | 64 ++++ tests/fun/meta/red.cc | 4 tests/morpho/levelings.cc | 66 ++++ tests/morpho/red_erosion.cc | 41 ++ tests/morpho/red_erosion3.cc | 65 ++++ tests/value/mixin.cc | 14 24 files changed, 860 insertions(+), 1665 deletions(-) Index: abraham/tests/morpho/levelings.cc --- abraham/tests/morpho/levelings.cc (revision 0) +++ abraham/tests/morpho/levelings.cc (revision 0) @@ -0,0 +1,66 @@ +#include <mln/core/image/image2d.hh> +#include <mln/io/ppm/save.hh> +#include <mln/io/ppm/load.hh> +#include <mln/value/int_u8.hh> +#include <mln/morpho/vector_median.hh> +#include <mln/morpho/autarkical_leveling.hh> +#include <mln/fun/meta/red.hh> +#include <mln/value/rgb8.hh> +#include <mln/value/mixin.hh> +#include <mln/core/image/fun_image.hh> +#include <mln/core/image/violent_cast_image.hh> + +namespace mln +{ + struct red_only + { + template <unsigned n> + value::rgb<n> max_() const + { + return value::rgb<n>(mln_max(typename value::rgb<n>::red_t), 0, 0); + } + + value::rgb8 max () const + { + return value::rgb8(255, 0, 0); + } + + template <unsigned n> + bool less(const value::rgb<n>& a, const value::rgb<n>& b) + { + return a.red() < b.red(); + } + }; + +} + + +int main (int argc, const char * argv[]) +{ + using namespace mln; + using namespace value; + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " in.pgm [other_files.pgm]" << std::endl; + return 1; + } + + typedef value::mixin<value::rgb8,red_only> Rgb; + + for (int i = 1; i < argc; ++i) + { + border::thickness = 2; + + image2d<rgb8> ima; + io::ppm::load(ima, argv[i]); + + std::string name(argv[i]); + name.erase(name.length() - 4); + + win::rectangle2d rect(8, 8); + + io::ppm::save(morpho::autarkical_leveling(ima, morpho::vector_median(ima, rect), rect), name.append("_autarkical_leveled.ppm")); + + } + return 0; +} Index: abraham/tests/morpho/red_erosion.cc --- abraham/tests/morpho/red_erosion.cc (revision 0) +++ abraham/tests/morpho/red_erosion.cc (revision 0) @@ -0,0 +1,41 @@ +#include <mln/core/image/image2d.hh> +#include <mln/io/ppm/save.hh> +#include <mln/io/ppm/load.hh> +#include <mln/value/int_u8.hh> +#include <mln/morpho/erosion.hh> +#include <mln/fun/meta/red.hh> +#include <mln/value/rgb8.hh> +#include <mln/core/image/fun_image.hh> + +int main (int argc, const char * argv[]) +{ + using namespace mln; + using namespace value; + + typedef image2d<int_u8> image2dint; + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " in.pgm [other_files.pgm]" << std::endl; + return 1; + } + + for (int i = 1; i < argc; ++i) + { + border::thickness = 2; + + image2d<rgb8> ima; + io::ppm::load(ima, argv[i]); + + mln::fun_image<meta::red <rgb8>, image2d<rgb8> > red(ima); + + std::string name(argv[i]); + name.erase(name.length() - 4); + + win::rectangle2d rect(5, 5); + morpho::erosion(red, rect); + + io::ppm::save(ima, name.append("_red_eroded.pgm")); + + } + return 0; +} Index: abraham/tests/morpho/red_erosion3.cc --- abraham/tests/morpho/red_erosion3.cc (revision 0) +++ abraham/tests/morpho/red_erosion3.cc (revision 0) @@ -0,0 +1,65 @@ +#include <mln/core/image/image2d.hh> +#include <mln/io/ppm/save.hh> +#include <mln/io/ppm/load.hh> +#include <mln/value/int_u8.hh> +#include <mln/morpho/erosion.hh> +#include <mln/fun/meta/red.hh> +#include <mln/value/rgb8.hh> +#include <mln/value/mixin.hh> +#include <mln/core/image/fun_image.hh> +#include <mln/core/image/violent_cast_image.hh> + +namespace mln +{ + struct red_only + { + template <unsigned n> + value::rgb<n> max_() const + { + return value::rgb<n>(mln_max(typename value::rgb<n>::red_t), 0, 0); + } + + value::rgb8 max () const + { + return value::rgb8(255, 0, 0); + } + + template <unsigned n> + bool less(const value::rgb<n>& a, const value::rgb<n>& b) + { + return a.red() < b.red(); + } + }; + +} + + +int main (int argc, const char * argv[]) +{ + using namespace mln; + using namespace value; + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " in.pgm [other_files.pgm]" << std::endl; + return 1; + } + + typedef value::mixin<value::rgb8,red_only> Rgb; + + for (int i = 1; i < argc; ++i) + { + border::thickness = 2; + + image2d<rgb8> ima; + io::ppm::load(ima, argv[i]); + + std::string name(argv[i]); + name.erase(name.length() - 4); + + win::rectangle2d rect(5, 5); + + io::ppm::save(violent_cast_image_<rgb8>(morpho::erosion(violent_cast_image_<Rgb>(ima), rect)), name.append("_red_eroded.pgm")); + + } + return 0; +} Index: abraham/tests/fun/meta/red.cc --- abraham/tests/fun/meta/red.cc (revision 3049) +++ abraham/tests/fun/meta/red.cc (working copy) @@ -1,6 +1,6 @@ #include <mln/fun/meta/red.hh> #include <mln/core/image/image2d.hh> -#include <mln/core/image/thru.hh> +#include <mln/core/image/fun_image.hh> namespace mln { @@ -52,7 +52,7 @@ c.r = 1; i(mln::point2d(2,1)) = c; - mln::thru<mln::meta::red <C>, mln::image2d<C> > out(i); + mln::fun_image<mln::meta::red <C>, mln::image2d<C> > out(i); mln_piter_(mln::image2d<C>) p(i.domain()); Index: abraham/tests/core/image/fun_image_const.cc --- abraham/tests/core/image/fun_image_const.cc (revision 0) +++ abraham/tests/core/image/fun_image_const.cc (revision 0) @@ -0,0 +1,64 @@ +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// +// 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. + +# include <mln/core/image/image2d.hh> +# include <mln/core/image/fun_image.hh> +# include <mln/fun/v2w2v/cos.hh> + +int main () +{ + + using namespace mln; + + typedef const image2d<double> I; + + double vs[6][5] = { + + { 12, -3, 8, -4, 6 }, + { -2, 22, -1, 45, -1 }, + { -1, -4, -4, -4, -1 }, + { -1, -4, -3, -4, -1 }, + { -1, -4, -5, -3, -1 }, + { -1, -1, -1, -1, -1 } + + }; + + I ima(make::image(vs)); + fun_image<mln::fun::v2w2v::cos<double>, I > out(ima); + + double i = 0; + + box_fwd_piter_<point2d> p(ima.domain()); + for_all (p) + { + out(p) = i; + i += 1./40.; + } + + for_all (p) + std::cout << out(p) << std::endl; +} Index: abraham/tests/core/image/fun_image_norm.cc --- abraham/tests/core/image/fun_image_norm.cc (revision 0) +++ abraham/tests/core/image/fun_image_norm.cc (revision 0) @@ -0,0 +1,63 @@ +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// +// 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. + +# include <mln/core/image/image2d.hh> +# include <mln/core/image/fun_image.hh> +# include <mln/fun/v2w_w2v/norm.hh> +# include <mln/algebra/vec.hh> +# include <mln/level/fill.hh> +# include <mln/core/image/violent_cast_image.hh> + +#include <mln/morpho/erosion.hh> + +int main () +{ + + using namespace mln; + typedef image2d<algebra::vec<2, double> > I; + + I ima(3, 2, 0); + + ima(point2d(0,0)).set (1, 1); + ima(point2d(0,1)).set (1, 3); + ima(point2d(1,0)).set (4, 4); + ima(point2d(1,1)).set (-1, 3); + ima(point2d(2,0)).set (23, 23); + ima(point2d(2,1)).set (3, 1); + + fun_image<mln::fun::v2w_w2v::l1_norm<algebra::vec<2, double>, double>, I > out(ima); + // level::fill(out, 1); + + win::rectangle2d rect(3, 3); + morpho::erosion(out, rect); + + + box_fwd_piter_<point2d> p(ima.domain()); + + for_all (p) + std::cout << ima(p) << std::endl; +} Index: abraham/tests/core/image/fun_image_v2v.cc --- abraham/tests/core/image/fun_image_v2v.cc (revision 0) +++ abraham/tests/core/image/fun_image_v2v.cc (revision 0) @@ -0,0 +1,56 @@ +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// +// 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. + +# include <mln/core/image/image2d.hh> +# include <mln/core/image/fun_image.hh> +# include <mln/fun/v2v/abs.hh> + +int main () +{ + + using namespace mln; + + typedef image2d<int> I; + + int vs[6][5] = { + + { -3, -3, -4, -4, -4 }, + { -2, -1, -1, -1, -1 }, + { -1, -4, -4, -4, -1 }, + { -1, -4, -3, -4, -1 }, + { -1, -4, -5, -3, -1 }, + { -1, -1, -1, -1, -1 } + + }; + + image2d<int> ima(make::image(vs)); + fun_image<mln::fun::v2v::abs<int>, image2d<int> > out(ima); + + box_fwd_piter_<point2d> p(ima.domain()); + for_all (p) + mln_assertion (out(p) >= 0); +} Index: abraham/tests/core/image/fun_image_v2w2v.cc --- abraham/tests/core/image/fun_image_v2w2v.cc (revision 0) +++ abraham/tests/core/image/fun_image_v2w2v.cc (revision 0) @@ -0,0 +1,64 @@ +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// +// 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. + +# include <mln/core/image/image2d.hh> +# include <mln/core/image/fun_image.hh> +# include <mln/fun/v2w2v/cos.hh> + +int main () +{ + + using namespace mln; + + typedef image2d<double> I; + + double vs[6][5] = { + + { 12, -3, 8, -4, 6 }, + { -2, 22, -1, 45, -1 }, + { -1, -4, -4, -4, -1 }, + { -1, -4, -3, -4, -1 }, + { -1, -4, -5, -3, -1 }, + { -1, -1, -1, -1, -1 } + + }; + + image2d<double> ima(make::image(vs)); + fun_image<mln::fun::v2w2v::cos<double>, image2d<double> > out(ima); + + double i = 0; + + box_fwd_piter_<point2d> p(ima.domain()); + for_all (p) + { + out(p) = i; + i += 1./40.; + } + + for_all (p) + std::cout << out(p) << std::endl; +} Index: abraham/tests/value/mixin.cc --- abraham/tests/value/mixin.cc (revision 3049) +++ abraham/tests/value/mixin.cc (working copy) @@ -83,14 +83,16 @@ value::rgb8 r(12, 13, 14); value::rgb8 s(13, 14, 15); + value::rgb8 t(13, 20, 17); - typedef value::mixin<value::rgb8,red_only> Rgb; + std::cout << mln_max(value::rgb8::red_t) << std::endl; - std::cout << ( my_violent_cast<Rgb>(r) < my_violent_cast<Rgb>(s) ) << std::endl; + typedef value::mixin<value::rgb8,red_only> Rgb; + assert(my_violent_cast<Rgb>(r) < my_violent_cast<Rgb>(s)); + assert(my_violent_cast<Rgb>(s) > my_violent_cast<Rgb>(r)); + assert(my_violent_cast<Rgb>(s) == my_violent_cast<Rgb>(t)); + assert(my_violent_cast<Rgb>(s) >= my_violent_cast<Rgb>(t)); -// std::cout -// << ( *(value::mixin<value::rgb8, value::op_less>*)(void*) &r < -// *(value::mixin<value::rgb8, value::op_less>*)(void*) &s ) -// << std::endl; + return 0; } Index: abraham/mln/morpho/autarkical_leveling.hh --- abraham/mln/morpho/autarkical_leveling.hh (revision 0) +++ abraham/mln/morpho/autarkical_leveling.hh (revision 0) @@ -0,0 +1,145 @@ +// 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. + +#ifndef MLN_MORPHO_AUTARKICAL_LEVELING_HH +# define MLN_MORPHO_AUTARKICAL_LEVELING_HH + +/// \file mln/morpho/autarkical_leveling.hh +/// +/// Morphological autarkical leveling filter. +/// +/// \todo The overloads are hidden and I don't know why! + +# include <mln/morpho/includes.hh> +# include <mln/morpho/general.hh> +# include <mln/accu/land.hh> +# include <mln/accu/land_basic.hh> +# include <mln/accu/min.hh> +# include <mln/accu/min_h.hh> +# include <mln/norm/l2.hh> + +namespace mln +{ + + namespace morpho + { + + /// Morphological autarkical_leveling. + template <typename I, typename W> + mln_concrete(I) + autarkical_leveling(const Image<I>& input, const Image<I>& marker, const Window<W>& win); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + // On set with centered window (overloads). + + template <typename I, typename W> + mln_concrete(I) + autarkical_leveling(const Image<I>& input_, const Image<I>& marker_, const Window<W>& win_) + { + trace::entering("morpho::impl::general_on_set_centered__autarkical_leveling"); + + typedef mln_concrete(I) O; + const I& input = exact(input_); + const I& marker = exact(marker_); + const W& win = exact(win_); + + O output; + output = clone(input); + + bool modification = true; + + mln_piter(I) p(input.domain()); + mln_qiter(W) q(win, p); + mln_qiter(W) r(win, p); + for_all(p) + { + mln_psite(W) v; + double min_dist = std::numeric_limits<double>::infinity(); + bool same_side = true; + + for_all(q) if (input.domain().has(q)) + { + for_all(r) if (input.domain().has(r) && q!=r) + if ((marker(q) - input(p)) * (marker(r) - input(p)) < 0) + { + same_side = false; + break; + } + + if (!same_side) + break; + + double dist = norm::l2(input(p) - marker(q)); + if (dist < min_dist) + { + min_dist = dist; + v = q; + } + } + if (same_side) + output(p) = marker(v); + else + output(p) = input(p); + } + + trace::exiting("morpho::impl::general_on_set_centered__autarkical_leveling"); + return output; + } + + + } // end of namespace morpho::impl + + + template <typename I, typename W> + inline + mln_concrete(I) + autarkical_leveling(const Image<I>& input, const Image<I>& marker, const Window<W>& win) + { + trace::entering("morpho::autarkical_leveling"); + mln_precondition(exact(input).has_data()); + mln_precondition(! exact(win).is_empty()); + + mln_concrete(I) output = impl::autarkical_leveling(input, marker, win); + + trace::exiting("morpho::autarkical_leveling"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::morpho + +} // end of namespace mln + + +#endif // ! MLN_MORPHO_AUTARKICAL_LEVELING_HH Index: abraham/mln/morpho/topo_wst.hh Index: abraham/mln/morpho/vector_median.hh --- abraham/mln/morpho/vector_median.hh (revision 0) +++ abraham/mln/morpho/vector_median.hh (revision 0) @@ -0,0 +1,129 @@ +// 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. + +#ifndef MLN_MORPHO_VECTOR_MEDIAN_HH +# define MLN_MORPHO_VECTOR_MEDIAN_HH + +/// \file mln/morpho/vector_median.hh +/// +/// Morphological vector median filter. +/// +/// \todo The overloads are hidden and I don't know why! + +# include <mln/morpho/includes.hh> +# include <mln/morpho/general.hh> +# include <mln/accu/land.hh> +# include <mln/accu/land_basic.hh> +# include <mln/accu/min.hh> +# include <mln/accu/min_h.hh> +# include <mln/norm/l2.hh> + +namespace mln +{ + + namespace morpho + { + + /// Morphological vector_median. + template <typename I, typename W> + mln_concrete(I) + vector_median(const Image<I>& input, const Window<W>& win); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + // On set with centered window (overloads). + + template <typename I, typename W> + mln_concrete(I) + vector_median(const Image<I>& input_, const Window<W>& win_) + { + trace::entering("morpho::impl::general_on_set_centered__vector_median"); + + typedef mln_concrete(I) O; + const I& input = exact(input_); + const W& win = exact(win_); + + O output; + output = clone(input); + + mln_piter(I) p(input.domain()); + mln_qiter(W) q(win, p); + mln_qiter(W) r(win, p); + for_all(p) + { + mln_psite(W) v; + double min_dist = std::numeric_limits<double>::infinity(); + for_all(q) if (input.domain().has(q)) + { + double dist = 0; + for_all(r) if (input.domain().has(r) && q!=r) + dist += norm::l2(input(r) - input(q)); + if (dist < min_dist) + { + min_dist = dist; + v = q; + } + } + output(p) = input(v); + } + + trace::exiting("morpho::impl::general_on_set_centered__vector_median"); + return output; + } + + + } // end of namespace morpho::impl + + + template <typename I, typename W> + inline + mln_concrete(I) + vector_median(const Image<I>& input, const Window<W>& win) + { + trace::entering("morpho::vector_median"); + mln_precondition(exact(input).has_data()); + mln_precondition(! exact(win).is_empty()); + + mln_concrete(I) output = impl::vector_median(input, win); + + trace::exiting("morpho::vector_median"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::morpho + +} // end of namespace mln + + +#endif // ! MLN_MORPHO_VECTOR_MEDIAN_HH
participants (1)
-
Alexandre Abraham