3758: Add make_edge_image in world::inter_pixel and few missing tests.

* mln/world/inter_pixel/dim2/make_edge_image.hh: new routine. * mln/world/inter_pixel/full2image.hh, * mln/world/inter_pixel/image2full.hh, * mln/world/inter_pixel/neighb2d.hh: update doc. * tests/Makefile.am, * tests/world/Makefile.am, * tests/world/inter_pixel/Makefile.am, * tests/world/inter_pixel/dim2/Makefile.am, * tests/world/inter_pixel/dim2/make_edge_image.cc, * tests/world/inter_pixel/image2full.cc: new tests. --- milena/ChangeLog | 17 +++ .../mln/world/inter_pixel/dim2/make_edge_image.hh | 104 ++++++++++++++++++++ milena/mln/world/inter_pixel/full2image.hh | 30 +++++- milena/mln/world/inter_pixel/image2full.hh | 29 +++++- milena/mln/world/inter_pixel/neighb2d.hh | 37 +++++--- milena/tests/Makefile.am | 3 +- milena/tests/world/Makefile.am | 2 + milena/tests/world/inter_pixel/Makefile.am | 13 +++ milena/tests/world/inter_pixel/dim2/Makefile.am | 10 ++ .../world/inter_pixel/dim2/make_edge_image.cc} | 66 +++++++------ .../world/inter_pixel/image2full.cc} | 60 +++++------- 11 files changed, 280 insertions(+), 91 deletions(-) create mode 100644 milena/mln/world/inter_pixel/dim2/make_edge_image.hh create mode 100644 milena/tests/world/Makefile.am create mode 100644 milena/tests/world/inter_pixel/Makefile.am create mode 100644 milena/tests/world/inter_pixel/dim2/Makefile.am copy milena/{mln/world/inter_pixel/full2image.hh => tests/world/inter_pixel/dim2/make_edge_image.cc} (55%) copy milena/{mln/world/inter_pixel/image2full.hh => tests/world/inter_pixel/image2full.cc} (60%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 9851a79..b4bb872 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,20 @@ +2009-05-05 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Add make_edge_image in world::inter_pixel and few missing tests. + + * mln/world/inter_pixel/dim2/make_edge_image.hh: new routine. + + * mln/world/inter_pixel/full2image.hh, + * mln/world/inter_pixel/image2full.hh, + * mln/world/inter_pixel/neighb2d.hh: update doc. + + * tests/Makefile.am, + * tests/world/Makefile.am, + * tests/world/inter_pixel/Makefile.am, + * tests/world/inter_pixel/dim2/Makefile.am, + * tests/world/inter_pixel/dim2/make_edge_image.cc, + * tests/world/inter_pixel/image2full.cc: new tests. + 2009-05-05 Fabien Freling <fabien.freling@lrde.epita.fr> Update inter_pixel files to match coding style. diff --git a/milena/mln/world/inter_pixel/dim2/make_edge_image.hh b/milena/mln/world/inter_pixel/dim2/make_edge_image.hh new file mode 100644 index 0000000..0624067 --- /dev/null +++ b/milena/mln/world/inter_pixel/dim2/make_edge_image.hh @@ -0,0 +1,104 @@ +// Copyright (C) 2009 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_WORLD_INTER_PIXEL_DIM2_MAKE_EDGE_IMAGE_HH +# define MLN_WORLD_INTER_PIXEL_DIM2_MAKE_EDGE_IMAGE_HH + +/// \file mln/world/inter_pixel/dim2/make_edge_image.hh +/// +/// Construct a valued image of edges. + +# include <mln/core/image/extension_ima.hh> +# include <mln/core/image/image_if.hh> + +# include <mln/core/routine/extend.hh> + +# include <mln/world/inter_pixel/neighb2d.hh> +# include <mln/world/inter_pixel/dim2/is_edge.hh> +# include <mln/data/fill.hh> + +namespace mln +{ + + namespace world + { + + namespace inter_pixel + { + + namespace dim2 + { + + template <typename I, typename F> + mln_concrete(I) + make_edge_image(const Image<I>& input_, const Function_vv2v<F>& f_) + { + trace::entering("world::inter_pixel::dim2::make_edge_image"); + + const I& input = exact(input_); + const F& f = exact(f_); + mln_precondition(input.is_valid()); + + typedef image_if<const image2d<value::int_u<8u> >, + world::inter_pixel::dim2::is_edge> edges_t; + edges_t edges = input | is_edge(); + typedef extension_ima<const edges_t,const I> edges_ext_t; + edges_ext_t edges_ext = extend(edges, input); + + mln_piter(edges_ext_t) p(edges_ext.domain()); + dbl_neighb2d nbh = e2c(); + mln_niter(dbl_neighb2d) n(nbh, p); + mln_value(I) vs[2]; + + mln_concrete(I) output; + initialize(output, input); + data::fill(output, literal::zero); + + for_all(p) + { + unsigned i = 0; + for_all(n) + { + mln_assertion(i < 2); + vs[i++] = input(n); + } + output(p) = f(vs[0], vs[1]); + } + + trace::exiting("world::inter_pixel::dim2::make_edge_image"); + return output; + } + + } // end of namespace mln::world::inter_pixel::dim2 + + } // end of namespace mln::world::inter_pixel + + } // end of namespace mln::world + +} // end of namespace mln + +#endif // ! MLN_WORLD_INTER_PIXEL_DIM2_MAKE_EDGE_IMAGE_HH diff --git a/milena/mln/world/inter_pixel/full2image.hh b/milena/mln/world/inter_pixel/full2image.hh index d08ada2..c116964 100644 --- a/milena/mln/world/inter_pixel/full2image.hh +++ b/milena/mln/world/inter_pixel/full2image.hh @@ -30,9 +30,16 @@ /// \file mln/world/inter_pixel/full.hh /// -/// FIXME: insert comment. +/// Convert an inter-pixel image to a classical image. +/// +/// FIXME: will NOT work if the image has an origin different from (0,0). # include <mln/core/image/image2d.hh> +# include <mln/geom/max_col.hh> +# include <mln/geom/max_row.hh> +# include <mln/geom/min_col.hh> +# include <mln/geom/min_row.hh> + namespace mln { @@ -43,6 +50,12 @@ namespace mln namespace inter_pixel { + /// Convert an inter-pixel image to a classical image. + /// + /// \param[in] input An inter-pixel image. + /// + /// \return A classical image without inter-pixel data. + // template <typename T> image2d<T> full2image(const image2d<T>& input); @@ -50,19 +63,26 @@ namespace mln # ifndef MLN_INCLUDE_ONLY + template <typename T> image2d<T> full2image(const image2d<T>& input) { - image2d<T> output((input.nrows() + 1) / 2, - (input.ncols() + 1) / 2); - for (int row = 0; row < input.nrows(); row += 2) - for (int col = 0; col < input.ncols(); col += 2) + trace::entering("world::inter_pixel::full2image"); + mln_precondition(input.is_valid()); + + image2d<T> output((input.nrows() + 1) / 2, (input.ncols() + 1) / 2); + + for (int row = geom::min_row(input); row <= geom::max_row(input); row += 2) + for (int col = geom::min_col(input); col <= geom::max_col(input); col += 2) opt::at(output, row / 2, col / 2) = opt::at(input, row, col); + + trace::exiting("world::inter_pixel::full2image"); return output; } + # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/world/inter_pixel/image2full.hh b/milena/mln/world/inter_pixel/image2full.hh index 0c32ad1..03102f7 100644 --- a/milena/mln/world/inter_pixel/image2full.hh +++ b/milena/mln/world/inter_pixel/image2full.hh @@ -30,9 +30,16 @@ /// \file mln/world/inter_pixel/full.hh /// -/// FIXME: insert comment. +/// Convert a classical 2D image to an inter-pixel image. +/// +/// FIXME: will NOT work if the image has an origin different from (0,0). # include <mln/core/image/image2d.hh> +# include <mln/geom/max_col.hh> +# include <mln/geom/max_row.hh> +# include <mln/geom/min_col.hh> +# include <mln/geom/min_row.hh> + namespace mln { @@ -43,6 +50,12 @@ namespace mln namespace inter_pixel { + /// Convert a classical 2D image to an inter-pixel image. + /// + /// \param[in] input A 2d image. + /// + /// \return An inter-pixel image. + // template <typename T> image2d<T> image2full(const image2d<T>& input); @@ -50,18 +63,24 @@ namespace mln # ifndef MLN_INCLUDE_ONLY + template <typename T> image2d<T> image2full(const image2d<T>& input) { - image2d<T> output(2 * input.nrows() - 1, - 2 * input.ncols() - 1); - for (int row = 0; row < input.nrows(); ++row) - for (int col = 0; col < input.ncols(); ++col) + trace::entering("world::inter_pixel::image2full"); + mln_precondition(input.is_valid()); + + image2d<T> output(2 * input.nrows() - 1, 2 * input.ncols() - 1); + for (int row = geom::min_row(input); row <= geom::max_row(input); ++row) + for (int col = geom::min_col(input); col <= geom::max_col(input); ++col) opt::at(output, 2 * row, 2 * col) = opt::at(input, row, col); + + trace::exiting("world::inter_pixel::image2full"); return output; } + # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/world/inter_pixel/neighb2d.hh b/milena/mln/world/inter_pixel/neighb2d.hh index 6ad7101..a61edeb 100644 --- a/milena/mln/world/inter_pixel/neighb2d.hh +++ b/milena/mln/world/inter_pixel/neighb2d.hh @@ -30,7 +30,8 @@ /// \file mln/world/inter_pixel/neighb2d.hh /// -/// FIXME: insert comment. +/// Common neighborhood on inter-pixel images. + # include <mln/core/alias/neighb2d.hh> # include <mln/make/double_neighb2d.hh> @@ -45,9 +46,13 @@ namespace mln namespace inter_pixel { + /// Double neighborhood used for inter-pixel images. typedef neighb< win::multiple<window2d, dim2::is_row_odd> > dbl_neighb2d; + /// C4 neighborhood on pixels centered on an edge. const dbl_neighb2d& e2c(); + + /// C8 neighborhood on edges centered on an edge. const dbl_neighb2d& e2e(); @@ -56,27 +61,33 @@ namespace mln const dbl_neighb2d& e2c() { static bool e2c_h[] = { 0, 1, 0, - 0, 0, 0, - 0, 1, 0 }; + 0, 0, 0, + 0, 1, 0 }; + static bool e2c_v[] = { 0, 0, 0, - 1, 0, 1, - 0, 0, 0 }; + 1, 0, 1, + 0, 0, 0 }; + static dbl_neighb2d nbh = make::double_neighb2d(dim2::is_row_odd(), e2c_h, e2c_v); return nbh; } + + const dbl_neighb2d& e2e() { static bool e2e_h[] = { 0, 0, 1, 0, 0, - 0, 1, 0, 1, 0, - 0, 0, 0, 0, 0, - 0, 1, 0, 1, 0, - 0, 0, 1, 0, 0 }; + 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, + 0, 0, 1, 0, 0 }; + static bool e2e_v[] = { 0, 0, 0, 0, 0, - 0, 1, 0, 1, 0, - 1, 0, 0, 0, 1, - 0, 1, 0, 1, 0, - 0, 0, 0, 0, 0 }; + 0, 1, 0, 1, 0, + 1, 0, 0, 0, 1, + 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0 }; + static dbl_neighb2d nbh = make::double_neighb2d(dim2::is_row_odd(), e2e_h, e2e_v); return nbh; } diff --git a/milena/tests/Makefile.am b/milena/tests/Makefile.am index 9945b19..23cb39e 100644 --- a/milena/tests/Makefile.am +++ b/milena/tests/Makefile.am @@ -46,7 +46,8 @@ SUBDIRS = \ unit_test \ util \ value \ - win + win \ + world check_PROGRAMS = \ diff --git a/milena/tests/world/Makefile.am b/milena/tests/world/Makefile.am new file mode 100644 index 0000000..7a41ecd --- /dev/null +++ b/milena/tests/world/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = \ + inter_pixel diff --git a/milena/tests/world/inter_pixel/Makefile.am b/milena/tests/world/inter_pixel/Makefile.am new file mode 100644 index 0000000..cffbcdd --- /dev/null +++ b/milena/tests/world/inter_pixel/Makefile.am @@ -0,0 +1,13 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +include $(top_srcdir)/milena/tests/tests.mk + +SUBDIRS = \ + dim2 + +check_PROGRAMS = \ + image2full + +image2full_SOURCES = image2full.cc + +TESTS = $(check_PROGRAMS) diff --git a/milena/tests/world/inter_pixel/dim2/Makefile.am b/milena/tests/world/inter_pixel/dim2/Makefile.am new file mode 100644 index 0000000..51fef42 --- /dev/null +++ b/milena/tests/world/inter_pixel/dim2/Makefile.am @@ -0,0 +1,10 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + make_edge_image + +make_edge_image_SOURCES = make_edge_image.cc + +TESTS = $(check_PROGRAMS) diff --git a/milena/mln/world/inter_pixel/full2image.hh b/milena/tests/world/inter_pixel/dim2/make_edge_image.cc similarity index 55% copy from milena/mln/world/inter_pixel/full2image.hh copy to milena/tests/world/inter_pixel/dim2/make_edge_image.cc index d08ada2..34f16cc 100644 --- a/milena/mln/world/inter_pixel/full2image.hh +++ b/milena/tests/world/inter_pixel/dim2/make_edge_image.cc @@ -25,51 +25,57 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_WORLD_INTER_PIXEL_FULL_HH -# define MLN_WORLD_INTER_PIXEL_FULL_HH - -/// \file mln/world/inter_pixel/full.hh +/// \file tests/world/inter_pixel/dim2/make_edge_image.cc /// -/// FIXME: insert comment. +/// Tests on mln::world::inter_pixel::dim2::make_edge_image + + +#include <mln/core/image/image2d.hh> +#include <mln/world/inter_pixel/dim2/make_edge_image.hh> +#include <mln/value/int_u8.hh> +#include <mln/make/image.hh> +#include <mln/math/abs.hh> +#include <mln/level/compare.hh> -# include <mln/core/image/image2d.hh> namespace mln { - namespace world + struct myfun : Function_vv2v<myfun> { + typedef mln::value::int_u8 result; - namespace inter_pixel + result operator()(const value::int_u8& v1, const value::int_u8& v2) const { + return math::abs(v1-v2); + } + }; - template <typename T> - image2d<T> - full2image(const image2d<T>& input); +} -# ifndef MLN_INCLUDE_ONLY - template <typename T> - image2d<T> - full2image(const image2d<T>& input) - { - image2d<T> output((input.nrows() + 1) / 2, - (input.ncols() + 1) / 2); - for (int row = 0; row < input.nrows(); row += 2) - for (int col = 0; col < input.ncols(); col += 2) - opt::at(output, row / 2, col / 2) = - opt::at(input, row, col); - return output; - } - -# endif // ! MLN_INCLUDE_ONLY +int main() +{ + using namespace mln; + value::int_u8 vals[][5] = { { 3, 0, 4, 0, 5 }, + { 0, 0, 0, 0, 0 }, + { 1, 0, 3, 0, 6 }, + { 0, 0, 0, 0, 0 }, + { 8, 0, 7, 0, 3 } }; - } // end of namespace mln::world::inter_pixel + value::int_u8 refs[][5] = { { 0, 1, 0, 1, 0 }, + { 2, 0, 1, 0, 1 }, + { 0, 2, 0, 3, 0 }, + { 7, 0, 4, 0, 3 }, + { 0, 1, 0, 4, 0 } }; - } // end of namespace mln::world + typedef image2d<value::int_u8> ima_t; + ima_t ima = make::image(vals); + ima_t ref = make::image(refs); -} // end of namespace mln + ima_t res = world::inter_pixel::dim2::make_edge_image(ima, myfun()); -#endif // ! MLN_WORLD_INTER_PIXEL_FULL + mln_assertion(res == ref); +} diff --git a/milena/mln/world/inter_pixel/image2full.hh b/milena/tests/world/inter_pixel/image2full.cc similarity index 60% copy from milena/mln/world/inter_pixel/image2full.hh copy to milena/tests/world/inter_pixel/image2full.cc index 0c32ad1..06398a1 100644 --- a/milena/mln/world/inter_pixel/image2full.hh +++ b/milena/tests/world/inter_pixel/image2full.cc @@ -25,50 +25,36 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_WORLD_INTER_PIXEL_FULL_HH -# define MLN_WORLD_INTER_PIXEL_FULL_HH - -/// \file mln/world/inter_pixel/full.hh +/// \file tests/world/inter_pixel/image2full.cc /// -/// FIXME: insert comment. +/// Tests on mln::world::inter_pixel::image2full -# include <mln/core/image/image2d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/make/image.hh> +#include <mln/value/int_u8.hh> +#include <mln/level/compare.hh> +#include <mln/world/inter_pixel/image2full.hh> -namespace mln +int main() { + using namespace mln; - namespace world - { - - namespace inter_pixel - { - - template <typename T> - image2d<T> - image2full(const image2d<T>& input); - - -# ifndef MLN_INCLUDE_ONLY - - template <typename T> - image2d<T> - image2full(const image2d<T>& input) - { - image2d<T> output(2 * input.nrows() - 1, - 2 * input.ncols() - 1); - for (int row = 0; row < input.nrows(); ++row) - for (int col = 0; col < input.ncols(); ++col) - opt::at(output, 2 * row, 2 * col) = opt::at(input, row, col); - return output; - } - -# endif // ! MLN_INCLUDE_ONLY + value::int_u8 vals[][3] = { { 3, 4, 5 }, + { 1, 3, 6 }, + { 8, 7, 3 } } ; + value::int_u8 refs[][5] = { { 3, 0, 4, 0, 5 }, + { 0, 0, 0, 0, 0 }, + { 1, 0, 3, 0, 6 }, + { 0, 0, 0, 0, 0 }, + { 8, 0, 7, 0, 3 } }; - } // end of namespace mln::world::inter_pixel + typedef image2d<value::int_u8> ima_t; + ima_t ima = make::image(vals); + ima_t ref = make::image(refs); - } // end of namespace mln::world + ima_t ima_l = world::inter_pixel::image2full(ima); -} // end of namespace mln + mln_assertion(ima_l == ref); -#endif // ! MLN_WORLD_INTER_PIXEL_FULL +} -- 1.5.6.5
participants (1)
-
Guillaume Lazzara