4412: New filters in Scribo.

* filter/object_links_bbox_h_ratio.hh, * filter/object_links_bbox_overlap.hh, * filter/object_links_bbox_ratio.hh, * filter/object_links_bbox_w_ratio.hh, * filter/object_links_bottom_aligned.hh, * filter/object_links_non_aligned_simple.hh: New. --- scribo/ChangeLog | 11 ++ scribo/filter/object_links_bbox_h_ratio.hh | 97 ++++++++++++++ scribo/filter/object_links_bbox_overlap.hh | 131 +++++++++++++++++++ scribo/filter/object_links_bbox_ratio.hh | 111 ++++++++++++++++ scribo/filter/object_links_bbox_w_ratio.hh | 97 ++++++++++++++ scribo/filter/object_links_bottom_aligned.hh | 115 ++++++++++++++++ scribo/filter/object_links_non_aligned_simple.hh | 151 ++++++++++++++++++++++ 7 files changed, 713 insertions(+), 0 deletions(-) create mode 100644 scribo/filter/object_links_bbox_h_ratio.hh create mode 100644 scribo/filter/object_links_bbox_overlap.hh create mode 100644 scribo/filter/object_links_bbox_ratio.hh create mode 100644 scribo/filter/object_links_bbox_w_ratio.hh create mode 100644 scribo/filter/object_links_bottom_aligned.hh create mode 100644 scribo/filter/object_links_non_aligned_simple.hh diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 1b40996..06940eb 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,16 @@ 2009-08-28 Guillaume Lazzara <lazzara@lrde.epita.fr> + New filters in Scribo. + + * filter/object_links_bbox_h_ratio.hh, + * filter/object_links_bbox_overlap.hh, + * filter/object_links_bbox_ratio.hh, + * filter/object_links_bbox_w_ratio.hh, + * filter/object_links_bottom_aligned.hh, + * filter/object_links_non_aligned_simple.hh: New. + +2009-08-28 Guillaume Lazzara <lazzara@lrde.epita.fr> + * debug/decision_image.hh: New debug routine. 2009-08-28 Guillaume Lazzara <lazzara@lrde.epita.fr> diff --git a/scribo/filter/object_links_bbox_h_ratio.hh b/scribo/filter/object_links_bbox_h_ratio.hh new file mode 100644 index 0000000..6ced8e6 --- /dev/null +++ b/scribo/filter/object_links_bbox_h_ratio.hh @@ -0,0 +1,97 @@ +// 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 SCRIBO_FILTER_OBJECT_LINKS_BBOX_H_RATIO_HH +# define SCRIBO_FILTER_OBJECT_LINKS_BBOX_H_RATIO_HH + +/// \file +/// +/// Invalidate links between two objects with too different height or +/// width. + + +# include <mln/util/array.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/object_links.hh> +# include <scribo/core/object_image.hh> +# include <scribo/filter/object_links_bbox_ratio.hh> + +namespace scribo +{ + + namespace filter + { + + using namespace mln; + + /*! \brief Invalidate links between two objects with too different + height. + + \param[in] objects An object image. + \param[in] links Link objects information. + \param[in] min_h_ratio The minimum height ratio of two linked + bounding boxes. + + \result A filtered object link information. + */ + template <typename L> + object_links<L> + object_links_bbox_h_ratio(const object_image(L)& objects, + const object_links<L>& links, + float min_h_ratio); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L> + object_links<L> + object_links_bbox_h_ratio(const object_image(L)& objects, + const object_links<L>& links, + float min_h_ratio) + { + trace::entering("scribo::filter::object_links_bbox_h_ratio"); + + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + + object_links<L> + output = object_links_bbox_ratio(objects, links, 0, min_h_ratio); + + trace::exiting("scribo::filter::object_links_bbox_h_ratio"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::filter + +} // end of namespace scribo + + +#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BBOX_H_RATIO_HH diff --git a/scribo/filter/object_links_bbox_overlap.hh b/scribo/filter/object_links_bbox_overlap.hh new file mode 100644 index 0000000..ff65e92 --- /dev/null +++ b/scribo/filter/object_links_bbox_overlap.hh @@ -0,0 +1,131 @@ +// 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 SCRIBO_FILTER_OBJECT_LINKS_BBOX_OVERLAP_HH +# define SCRIBO_FILTER_OBJECT_LINKS_BBOX_OVERLAP_HH + +/// \file +/// +/// Invalidate links between two objects having their bounding box +/// overlapping too much. + + +# include <mln/util/array.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/object_links.hh> +# include <scribo/core/object_image.hh> +# include <scribo/filter/object_links_bbox_ratio.hh> + +namespace scribo +{ + + namespace filter + { + + using namespace mln; + + /*! \brief Invalidate links between two objects having their bounding box + overlapping too much. + + \param[in] objects An object image. + \param[in] links Link objects information. + \param[in] max_overlap_ratio The maximum ratio of the overlapping + areas. + + \result A filtered object link information. + */ + template <typename L> + object_links<L> + object_links_bbox_overlap(const object_image(L)& objects, + const object_links<L>& links, + float max_overlap_ratio); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L> + object_links<L> + object_links_bbox_overlap(const object_image(L)& objects, + const object_links<L>& links, + float max_overlap_ratio) + { + trace::entering("scribo::filter::object_links_bbox_overlap"); + + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + mln_precondition(objects.id_() == links.objects_id_()); + + typedef typename object_image(L)::bbox_t bbox_t; + const mln::util::array<bbox_t>& bboxes = objects.bboxes(); + object_links<L> output(links); + + for_all_components(i, objects.bboxes()) + if (links(i) != i) + { + bool has_intersection = true; + mln_site(L) pmin, pmax; + for (unsigned dim = 0; dim < mln_site_(L)::dim; ++dim) + { + pmin[dim] = math::max(bboxes(i).pmin()[dim], + bboxes(links[i]).pmin()[dim]); + pmax[dim] = math::min(bboxes(i).pmax()[dim], + bboxes(links[i]).pmax()[dim]); + + if (pmin[dim] > pmax[dim]) + { + has_intersection = false; + break; + } + } + + if (!has_intersection) + continue; + + mln_box(L) interbbox(pmin, pmax); + float + ratio_i = interbbox.nsites() /(float)bboxes(i).nsites(), + ratio_link_i = interbbox.nsites() /(float)bboxes(links(i)).nsites(); + + if (ratio_i >= max_overlap_ratio + || ratio_link_i >= max_overlap_ratio) + output[i] = i; + } + + trace::exiting("scribo::filter::object_links_bbox_overlap"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::filter + +} // end of namespace scribo + + +#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BBOX_OVERLAP_HH diff --git a/scribo/filter/object_links_bbox_ratio.hh b/scribo/filter/object_links_bbox_ratio.hh new file mode 100644 index 0000000..3cd0c7e --- /dev/null +++ b/scribo/filter/object_links_bbox_ratio.hh @@ -0,0 +1,111 @@ +// 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 SCRIBO_FILTER_OBJECT_LINKS_BBOX_RATIO_HH +# define SCRIBO_FILTER_OBJECT_LINKS_BBOX_RATIO_HH + +/// \file +/// +/// Invalidate links between two objects with too different height or +/// width. + + +# include <mln/util/array.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/object_links.hh> +# include <scribo/core/object_image.hh> + +namespace scribo +{ + + namespace filter + { + + using namespace mln; + + /*! \brief Invalidate links between two objects with too different + height or width. + + \param[in] objects An object image. + \param[in] links Link objects information. + \param[in] dim The dimension to use to compare bbox length. + \param[in] min_ratio The minimum length ratio of two linked + bounding boxes. + + \result A filtered object link information. + */ + template <typename L> + object_links<L> + object_links_bbox_ratio(const object_image(L)& objects, + const object_links<L>& links, + unsigned dim, + float min_ratio); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L> + object_links<L> + object_links_bbox_ratio(const object_image(L)& objects, + const object_links<L>& links, + unsigned dim, + float min_ratio) + { + trace::entering("scribo::filter::object_links_bbox_ratio"); + + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + + object_links<L> output(links); + for (unsigned i = 1; i < links.size(); ++i) + { + float + lmin = objects.bbox(i).pmax()[dim] - objects.bbox(i).pmin()[dim], + lmax = objects.bbox(links(i)).pmax()[dim] + - objects.bbox(links(i)).pmin()[dim]; + + if (lmin > lmax) + std::swap(lmin, lmax); + + if (lmin / lmax < min_ratio) + output(i) = i; + } + + trace::exiting("scribo::filter::object_links_bbox_ratio"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::filter + +} // end of namespace scribo + + +#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BBOX_RATIO_HH diff --git a/scribo/filter/object_links_bbox_w_ratio.hh b/scribo/filter/object_links_bbox_w_ratio.hh new file mode 100644 index 0000000..7cc99c3 --- /dev/null +++ b/scribo/filter/object_links_bbox_w_ratio.hh @@ -0,0 +1,97 @@ +// 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 SCRIBO_FILTER_OBJECT_LINKS_BBOX_W_RATIO_HH +# define SCRIBO_FILTER_OBJECT_LINKS_BBOX_W_RATIO_HH + +/// \file +/// +/// Invalidate links between two objects with too different height or +/// width. + + +# include <mln/util/array.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/object_links.hh> +# include <scribo/core/object_image.hh> +# include <scribo/filter/object_links_bbox_ratio.hh> + +namespace scribo +{ + + namespace filter + { + + using namespace mln; + + /*! \brief Invalidate links between two objects with too different + width. + + \param[in] objects An object image. + \param[in] links Link objects information. + \param[in] min_w_ratio The minimum width ratio of two linked + bounding boxes. + + \result A filtered object link information. + */ + template <typename L> + object_links<L> + object_links_bbox_w_ratio(const object_image(L)& objects, + const object_links<L>& links, + float min_w_ratio); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L> + object_links<L> + object_links_bbox_w_ratio(const object_image(L)& objects, + const object_links<L>& links, + float min_w_ratio) + { + trace::entering("scribo::filter::object_links_bbox_w_ratio"); + + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + + object_links<L> + output = object_links_bbox_ratio(objects, links, 1, min_w_ratio); + + trace::exiting("scribo::filter::object_links_bbox_w_ratio"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::filter + +} // end of namespace scribo + + +#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BBOX_W_RATIO_HH diff --git a/scribo/filter/object_links_bottom_aligned.hh b/scribo/filter/object_links_bottom_aligned.hh new file mode 100644 index 0000000..0846203 --- /dev/null +++ b/scribo/filter/object_links_bottom_aligned.hh @@ -0,0 +1,115 @@ +// 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 SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH +# define SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH + +/// \file +/// +/// Invalidate links between two objects if their bottom are not +/// aligned. + + +# include <mln/util/array.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/object_links.hh> +# include <scribo/core/object_image.hh> + +# include <scribo/filter/object_links_non_aligned_simple.hh> + +namespace scribo +{ + + namespace filter + { + + using namespace mln; + + /*! \brief Invalidate links between two objects if their bottom are not + aligned. + + \param[in] objects An object image. + \param[in] links Object links information. + \param[in] dim Choose the dimension on which applying the + filter. + \param[in] max_delta Maximum delta. + + \verbatim + + ------ + | | + ------ | | + | | | | + | x------------x | + | | | | v + ------ ~ ~ ~ |~ ~ | ~ ~ ~ + object1 | | | => delta, must be < to max_delta + ------ ~ ~ ~ + object2 ^ + + \endverbatim + + */ + template <typename L> + object_links<L> + object_links_bottom_aligned(const object_image(L)& objects, + const object_links<L>& links, + unsigned max_delta); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L> + object_links<L> + object_links_bottom_aligned(const object_image(L)& objects, + const object_links<L>& links, + unsigned max_delta) + { + trace::entering("scribo::filter::object_links_bottom_aligned"); + + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + + object_links<L> + output = object_links_non_aligned_simple(objects, links, + 1, 1, + max_delta); + + trace::exiting("scribo::filter::object_links_bottom_aligned"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::filter + +} // end of namespace scribo + + +#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_SIMPLE_HH diff --git a/scribo/filter/object_links_non_aligned_simple.hh b/scribo/filter/object_links_non_aligned_simple.hh new file mode 100644 index 0000000..e302fcf --- /dev/null +++ b/scribo/filter/object_links_non_aligned_simple.hh @@ -0,0 +1,151 @@ +// 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 SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_SIMPLE_HH +# define SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_SIMPLE_HH + +/// \file +/// +/// Invalidate links between two non aligned objects. + + +# include <mln/util/array.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/object_links.hh> +# include <scribo/core/object_image.hh> + +namespace scribo +{ + + namespace filter + { + + using namespace mln; + + /*! \brief Invalidate links between two non aligned objects. + Alignment is based on a given edge of object bounding boxes. + + \param[in] objects An object image. + \param[in] links Object links information. + \param[in] dim Choose the dimension on which applying the + filter. + \param[in] max_delta Maximum delta. + + + Exemple with dim == 1 and edge == 1 (bottom + horizontal filter): + + \verbatim + + ------ + | | + ------ | | + | | | | + | x------------x | + | | | | v + ------ ~ ~ ~ |~ ~ | ~ ~ ~ + object1 | | | => delta, must be < to max_delta + ------ ~ ~ ~ + object2 ^ + + \endverbatim + + */ + template <typename L> + object_links<L> + object_links_non_aligned_simple(const object_image(L)& objects, + const object_links<L>& links, + unsigned dim, + unsigned edge, + unsigned max_delta); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L> + object_links<L> + object_links_non_aligned_simple(const object_image(L)& objects, + const object_links<L>& links, + unsigned dim, + unsigned edge, + unsigned max_delta) + { + trace::entering("scribo::filter::object_links_non_aligned_simple"); + + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + + typedef typename object_image(L)::bbox_t bbox_t; + const mln::util::array<bbox_t>& bboxes = objects.bboxes(); + object_links<L> output(links); + unsigned delta; + + + if (edge == 0) + { + for_all_components(i, objects.bboxes()) + if (links[i] != i) + { + delta = bboxes[i].pmin()[dim] - bboxes[i].pmin()[dim]; + + if (delta > max_delta) + output[i] = i; + } + } + else if (edge == 1) + for_all_components(i, objects.bboxes()) + { + if (links[i] != i) + { + delta = bboxes[i].pmax()[dim] - bboxes[i].pmax()[dim]; + + if (delta > max_delta) + output[i] = i; + } + } + else + { + trace::warning("Invalid edge value..."); + trace::exiting("scribo::filter::object_links_non_aligned_simple"); + return output; + } + + + trace::exiting("scribo::filter::object_links_non_aligned_simple"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::filter + +} // end of namespace scribo + + +#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_SIMPLE_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara