milena r3720: Add world/ directory for inter_pixel images

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-04-28 Fabien Freling <fabien.freling@lrde.epita.fr> Add world/ directory for inter_pixel images. * mln/arith/all.hh: Update. * mln/arith/div.hh: New div operator. * mln/arith/div.spe.hh: New div operator. * mln/io/magick/save.hh: Update. * mln/io/plot/save.hh: Update. * mln/world/inter_pixel/full.hh: Convert standard image to inter_pixel image. * mln/world/inter_pixel/neighb2d.hh: Define standard inter_pixel neighborhood. --- arith/all.hh | 1 arith/div.hh | 289 ++++++++++++++++++++++++++++++++++++++++++ arith/div.spe.hh | 121 +++++++++++++++++ io/magick/save.hh | 2 io/plot/save.hh | 4 world/inter_pixel/full.hh | 77 +++++++++++ world/inter_pixel/neighb2d.hh | 83 ++++++++++++ 7 files changed, 574 insertions(+), 3 deletions(-) Index: trunk/milena/mln/world/inter_pixel/full.hh =================================================================== --- trunk/milena/mln/world/inter_pixel/full.hh (revision 0) +++ trunk/milena/mln/world/inter_pixel/full.hh (revision 3720) @@ -0,0 +1,77 @@ +// 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_FULL_HH +# define MLN_WORLD_INTER_PIXEL_FULL_HH + +/// \file mln/world/inter_pixel/full.hh +/// +/// FIXME: insert comment. + +# include <mln/core/image/image2d.hh> + +namespace mln +{ + + namespace world + { + + namespace inter_pixel + { + + 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; + } + + 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; + } + + } // end of namespace mln::world::inter_pixel + + } // end of namespace mln::world + +} // end of namespace mln + +#endif // ! MLN_WORLD_INTER_PIXEL_FULL Index: trunk/milena/mln/world/inter_pixel/neighb2d.hh =================================================================== --- trunk/milena/mln/world/inter_pixel/neighb2d.hh (revision 0) +++ trunk/milena/mln/world/inter_pixel/neighb2d.hh (revision 3720) @@ -0,0 +1,83 @@ +// 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_NEIGHB2D_HH +# define MLN_WORLD_INTER_PIXEL_NEIGHB2D_HH + +/// \file mln/world/inter_pixel/neighb2d.hh +/// +/// FIXME: insert comment. + +# include <mln/core/alias/neighb2d.hh> +# include <mln/make/double_neighb2d.hh> + +namespace mln +{ + + namespace world + { + + namespace inter_pixel + { + + typedef neighb< win::multiple<window2d, bool(*)(const point2d&)> > dbl_neighb2d; + + const dbl_neighb2d& e2c() + { + static bool e2c_h[] = { 0, 1, 0, + 0, 0, 0, + 0, 1, 0 }; + static bool e2c_v[] = { 0, 0, 0, + 1, 0, 1, + 0, 0, 0 }; + static dbl_neighb2d nbh = make::double_neighb2d(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 }; + 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 }; + static dbl_neighb2d nbh = make::double_neighb2d(is_row_odd, e2e_h, e2e_v); + return nbh; + } + + } // end of namespace mln::world::inter_pixel + + } // end of namespace mln::world + +} // end of namespace mln + +#endif // ! MLN_WORLD_INTER_PIXEL_NEIGHB2D Index: trunk/milena/mln/arith/div.hh =================================================================== --- trunk/milena/mln/arith/div.hh (revision 0) +++ trunk/milena/mln/arith/div.hh (revision 3720) @@ -0,0 +1,289 @@ +// 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_ARITH_DIV_HH +# define MLN_ARITH_DIV_HH + +/// \file mln/arith/div.hh +/// +/// Point-wise division between images. +/// +/// \todo Speedup; some versions are not optimal. + +# include <mln/arith/includes.hh> + +// Specializations are in: +# include <mln/arith/div.spe.hh> + + +namespace mln +{ + + + namespace trait + { + + template <typename L, typename R> + struct set_binary_< op::div, Image, L, Image, R > + { + typedef mln_trait_op_div(mln_value(L), mln_value(R)) value; + typedef mln_ch_value(L, value) ret; + }; + + template <typename I, typename S> + struct set_binary_< op::div, Image, I, mln::value::Scalar, S > + { + typedef mln_trait_op_div(mln_value(I), S) value; + typedef mln_ch_value(I, value) ret; + }; + + } // end of namespace mln::trait + + + + template <typename L, typename R> + mln_trait_op_div(L,R) + operator/(const Image<L>& lhs, const Image<R>& rhs); + + template <typename L, typename R> + L& + operator/=(Image<L>& lhs, const Image<R>& rhs); + + + template <typename I, typename S> + mln_trait_op_div(I,S) + operator/(const Image<I>& ima, const value::Scalar<S>& s); + + template <typename I, typename S> + I& + operator/=(Image<I>& ima, const value::Scalar<S>& s); + + + + namespace arith + { + + /// Point-wise division of images \p lhs and \p rhs. + /*! + * \param[in] lhs First operand image. + * \param[in] rhs Second operand image. + * \param[out] output The result image. + * + * \pre \p output.domain == \p lhs.domain == \p rhs.domain + */ + template <typename L, typename R, typename O> + void div(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output); + + + /// Point-wise division of the value \p val to image \p input. + /*! + * \param[in] input The image. + * \param[in] val The value. + * \param[out] output The result image. + * + * \pre \p output.domain == \p input.domain + */ + template <typename I, typename V, typename O> + void div_cst(const Image<I>& input, const V& val, Image<O>& output); + + + /// Point-wise division of image \p rhs in image \p lhs. + /*! + * \param[in] lhs First operand image (subject to division). + * \param[in,out] rhs Second operand image (to div \p lhs). + * + * This addition performs: \n + * for all p of rhs.domain \n + * lhs(p) /= rhs(p) + * + * \pre \p rhs.domain <= \p lhs.domain + */ + template <typename L, typename R> + void div_inplace(Image<L>& lhs, const Image<R>& rhs); + + + } // end of namespace mln::arith + + + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L, typename R> + inline + mln_trait_op_div(L,R) + operator/(const Image<L>& lhs, const Image<R>& rhs) + { + mln_precondition(exact(rhs).domain() == exact(lhs).domain()); + mln_trait_op_div(L,R) tmp; + initialize(tmp, lhs); + arith::div(lhs, rhs, tmp); + return tmp; + } + + template <typename L, typename R> + inline + L& + operator/=(Image<L>& lhs, const Image<R>& rhs) + { + mln_precondition(exact(rhs).domain() == exact(lhs).domain()); + arith::div_inplace(lhs, rhs); + return exact(lhs); + } + + + template <typename I, typename S> + inline + mln_trait_op_div(I,S) + operator/(const Image<I>& ima, const value::Scalar<S>& s) + { + mln_precondition(exact(ima).is_valid()); + mln_precondition(s != 0); + mln_trait_op_div(I,S) tmp; + initialize(tmp, ima); + arith::div_cst(ima, exact(s), tmp); + return tmp; + } + + template <typename I, typename S> + inline + I& + operator/=(Image<I>& ima, const value::Scalar<S>& s) + { + mln_precondition(exact(ima).is_valid()); + arith::div_cst(ima, exact(s), ima); + return exact(ima); + } + + + + namespace arith + { + + namespace impl + { + + namespace generic + { + + template <typename L, typename R, typename O> + inline + void div_(const L& lhs, const R& rhs, O& output) + { + trace::entering("arith::impl::generic::div_"); + + mln_piter(L) p(lhs.domain()); + for_all(p) + output(p) = lhs(p) / rhs(p); + + trace::exiting("arith::impl::generic::div_"); + } + + template <typename L, typename R> + inline + void div_inplace_(L& lhs, const R& rhs) + { + trace::entering("arith::impl::generic::div_inplace_"); + + mln_piter(R) p(rhs.domain()); + for_all(p) + lhs(p) /= rhs(p); + + trace::exiting("arith::impl::generic::div_inplace_"); + } + + } // end of namespace mln::arith::impl::generic + + } // end of namespace mln::arith::impl + + + // Facades. + + template <typename L, typename R, typename O> + inline + void div(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output) + { + trace::entering("arith::div"); + + mln_precondition(exact(rhs).domain() == exact(lhs).domain()); + mln_precondition(exact(output).domain() == exact(lhs).domain()); + impl::div_(mln_trait_image_speed(L)(), exact(lhs), + mln_trait_image_speed(R)(), exact(rhs), + mln_trait_image_speed(O)(), exact(output)); + + trace::exiting("arith::div"); + } + + template <typename I, typename V, typename O> + inline + void div_cst(const Image<I>& input, const V& val, Image<O>& output) + { + trace::entering("arith::div_cst"); + + mln_precondition(exact(output).domain() == exact(input).domain()); + div(input, pw::cst(val) | exact(input).domain(), output); + // Calls the previous version. + + trace::exiting("arith::div_cst"); + } + + template <typename L, typename R> + inline + void div_inplace(Image<L>& lhs, const Image<R>& rhs) + { + trace::entering("arith::div_inplace"); + + mln_precondition(exact(rhs).domain() <= exact(lhs).domain()); + impl::div_inplace_(mln_trait_image_speed(L)(), exact(lhs), + mln_trait_image_speed(R)(), exact(rhs)); + + trace::exiting("arith::div_inplace"); + } + + template <typename I, typename V> + inline + void div_cst_inplace(Image<I>& input, const V& val) + { + trace::entering("arith::div_cst_inplace"); + + mln_precondition(exact(input).is_valid()); + div_inplace(input, pw::cst(val) | exact(input).domain()); + // Calls the previous version. + + trace::exiting("arith::div_cst_inplace"); + } + + } // end of namespace mln::arith + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_ARITH_DIV_HH Index: trunk/milena/mln/arith/all.hh =================================================================== --- trunk/milena/mln/arith/all.hh (revision 3719) +++ trunk/milena/mln/arith/all.hh (revision 3720) @@ -55,6 +55,7 @@ } # include <mln/arith/diff_abs.hh> +# include <mln/arith/div.hh> # include <mln/arith/min.hh> # include <mln/arith/minus.hh> # include <mln/arith/plus.hh> Index: trunk/milena/mln/arith/div.spe.hh =================================================================== --- trunk/milena/mln/arith/div.spe.hh (revision 0) +++ trunk/milena/mln/arith/div.spe.hh (revision 3720) @@ -0,0 +1,121 @@ +// 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_ARITH_DIV_SPE_HH +# define MLN_ARITH_DIV_SPE_HH + +/// \file mln/arith/div.spe.hh +/// +/// Specializations for mln::arith::div. + +# ifndef MLN_ARITH_DIV_HH +# error "Forbidden inclusion of *.spe.hh" +# endif // ! MLN_ARITH_DIV_HH + +# include <mln/arith/includes.hh> + + +# ifndef MLN_INCLUDE_ONLY + +namespace mln +{ + + namespace arith + { + + namespace impl + { + + namespace generic + { + template <typename L, typename R, typename O> + void div_(const L& lhs, const R& rhs, O& output); + + template <typename L, typename R> + void div_inplace_(L& lhs, const R& rhs); + + } + + template <typename L, typename R, typename O> + inline + void div_(trait::image::speed::any, const L& lhs, + trait::image::speed::any, const R& rhs, + trait::image::speed::any, O& output) + { + generic::div_(lhs, rhs, output); + } + + template <typename L, typename R, typename O> + inline + void div_(trait::image::speed::fastest, const L& lhs, + trait::image::speed::fastest, const R& rhs, + trait::image::speed::fastest, O& output) + { + trace::entering("arith::impl::div_"); + + mln_pixter(const L) lp(lhs); + mln_pixter(const R) rp(rhs); + mln_pixter(O) op(output); + for_all_3(lp, rp, op) + op.val() = lp.val() / rp.val(); + + trace::exiting("arith::impl::div_"); + } + + template <typename L, typename R> + inline + void div_inplace_(trait::image::speed::any, L& lhs, + trait::image::speed::any, const R& rhs) + { + generic::div_inplace_(lhs, rhs); + } + + template <typename L, typename R> + inline + void div_inplace_(trait::image::speed::fastest, L& lhs, + trait::image::speed::fastest, const R& rhs) + { + trace::entering("arith::impl::div_inplace_"); + + mln_pixter(L) lp(lhs); + mln_pixter(const R) rp(rhs); + for_all_2(rp, lp) + lp.val() /= rp.val(); + + trace::exiting("arith::impl::div_inplace_"); + } + + } // end of namespace mln::arith::impl + + } // end of namespace mln::arith + +} // end of namespace mln + +# endif // ! MLN_INCLUDE_ONLY + +#endif // ! MLN_ARITH_DIV_SPE_HH Index: trunk/milena/mln/io/magick/save.hh =================================================================== --- trunk/milena/mln/io/magick/save.hh (revision 3719) +++ trunk/milena/mln/io/magick/save.hh (revision 3720) @@ -102,7 +102,7 @@ mln::metal::equal<mln_value(I), value::rgb8>::value)) { std::cerr << "error: trying to save an unsupported format" << std::endl; - std::cerr << "formats supported: binary, 8bits grayscale (int_u8), 8bits truecolor (rgb8)" << std::endl; + std::cerr << "supported formats: binary, 8bits grayscale (int_u8), 8bits truecolor (rgb8)" << std::endl; abort(); } Index: trunk/milena/mln/io/plot/save.hh =================================================================== --- trunk/milena/mln/io/plot/save.hh (revision 3719) +++ trunk/milena/mln/io/plot/save.hh (revision 3720) @@ -87,7 +87,7 @@ trace::entering("mln::io::plot::save"); std::ofstream file_out(filename.c_str()); - for (int i = 0; i < ima.ninds(); ++i) + for (unsigned i = 0; i < ima.ninds(); ++i) file_out << start_value + i << ", " << ima.at_(i) << std::endl; trace::exiting("mln::io::plot::save"); @@ -101,7 +101,7 @@ trace::entering("mln::io::plot::save"); std::ofstream file_out(filename.c_str()); - for (int i = 0; i < arr.nelements(); ++i) + for (unsigned i = 0; i < arr.nelements(); ++i) file_out << start_value + i << ", " << arr[i] << std::endl; trace::exiting("mln::io::plot::save");
participants (1)
-
Fabien Freling