
--- scribo/ChangeLog | 4 + ...rs_vert_in_borders.hh => objects_in_borders.hh} | 83 +++++++++---------- 2 files changed, 43 insertions(+), 44 deletions(-) copy scribo/scribo/filter/{separators_vert_in_borders.hh => objects_in_borders.hh} (53%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index ea6bc10..d1d0ebf 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,3 +1,7 @@ +2013-04-08 Guillaume Lazzara <z@lrde.epita.fr> + + * scribo/filter/objects_in_borders.hh: New. + 2013-04-04 Guillaume Lazzara <z@lrde.epita.fr> Fix binarization tests. diff --git a/scribo/scribo/filter/separators_vert_in_borders.hh b/scribo/scribo/filter/objects_in_borders.hh similarity index 53% copy from scribo/scribo/filter/separators_vert_in_borders.hh copy to scribo/scribo/filter/objects_in_borders.hh index a836554..579c892 100644 --- a/scribo/scribo/filter/separators_vert_in_borders.hh +++ b/scribo/scribo/filter/objects_in_borders.hh @@ -1,5 +1,4 @@ -// Copyright (C) 2011, 2013 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -24,22 +23,20 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_FILTER_SEPARATORS_VERT_IN_BORDERS_HH -# define SCRIBO_FILTER_SEPARATORS_VERT_IN_BORDERS_HH +#ifndef SCRIBO_FILTER_OBJECTS_IN_BORDERS_HH +# define SCRIBO_FILTER_OBJECTS_IN_BORDERS_HH /// \file /// -/// \brief Invalidate vertical separators located close to the image -/// borders. -/// \todo Share same test canvas as text::merging. +/// \brief Invalidate false positive separators. +/// \todo Share same test canvas as text::merging. # include <mln/core/concept/image.hh> +# include <mln/geom/all.hh> # include <scribo/core/component_set.hh> -# include <scribo/core/document.hh> # include <scribo/util/box_is_included.hh> - namespace scribo { @@ -49,20 +46,25 @@ namespace scribo using namespace mln; - /*! \brief Invalidate vertical separators located close to the image + /*! \brief Invalidate components located close to the image borders. - \param[in,out] doc A document structure. + \param[in,out] components A component set. + \param[in] vratio Ratio to be used for evaluating the inner + border size in which vertical separators + will be invalidated. + \param[in] hratio Ratio to be used for evaluating the inner + border size in which horizontal separators + will be invalidated. - Warning: it does not remove separators from separator - image. It only invalidate separator components in their - respective component_set. + \warning It only invalidates components in the given + component_set. \verbatim ----------- |_!____!__| - | ! ! <--------- Separators located in this area are + | ! ! <--------- Components located in this area are | ! ! | invalidated. | ! ! | |_!____!__| @@ -75,22 +77,24 @@ namespace scribo */ template <typename L> void - separators_vert_in_borders(document<L>& doc); + objects_in_borders(component_set<L>& components, float vratio, float hratio); # ifndef MLN_INCLUDE_ONLY template <typename L> void - separators_vert_in_borders(document<L>& doc) + objects_in_borders(component_set<L>& components, float vratio, float hratio) { - mln_trace("scribo::filter::separators_vert_in_borders"); + mln_trace("scribo::filter::objects_in_borders"); - mln_precondition(doc.is_valid()); + mln_precondition(components.is_valid()); - const mln::image2d<mln::value::rgb8>& ima = doc.image(); + const L& ima = components.labeled_image(); - float border_size = std::min(43., 0.05 * ima.domain().width()); + unsigned + hborder_size = hratio * std::min(ima.domain().width(), ima.domain().height()), + vborder_size = vratio * std::min(ima.domain().width(), ima.domain().height()); /// pt /// ptl X------X--- @@ -105,11 +109,11 @@ namespace scribo /// point2d ptl = ima.domain().pmin(), - pt(geom::min_row(ima), geom::max_col(ima) - border_size), - ptr(border_size, geom::max_col(ima)), + pt(geom::min_row(ima), geom::max_col(ima) - vborder_size), + ptr(hborder_size, geom::max_col(ima)), pbr = ima.domain().pmax(), - pb(geom::max_row(ima), border_size), - pbl(geom::max_row(ima) - border_size, geom::min_col(ima)); + pb(geom::max_row(ima), vborder_size), + pbl(geom::max_row(ima) - hborder_size, geom::min_col(ima)); box2d bt(ptl, ptr), @@ -117,24 +121,15 @@ namespace scribo bb(pbl, pbr), bl(ptl, pb); - // Vertical separators - if (doc.has_vline_seps()) - { - component_set<L> vline = doc.vline_seps_comps().duplicate(); - for_all_comps(c, vline) - if (vline(c).is_valid()) - if (util::box_is_included(vline(c).bbox(), bt) - || util::box_is_included(vline(c).bbox(), br) - || util::box_is_included(vline(c).bbox(), bb) - || util::box_is_included(vline(c).bbox(), bl)) - { - vline(c).update_tag(component::Ignored); - } - - // FIXME: warning this call may produce inconsistent data - // Ignored components are still in the separator image... - doc.set_vline_separators(doc.vline_seps(), vline); - } + for_all_comps(c, components) + if (components(c).is_valid()) + if (util::box_is_included(components(c).bbox(), bt) + || util::box_is_included(components(c).bbox(), br) + || util::box_is_included(components(c).bbox(), bb) + || util::box_is_included(components(c).bbox(), bl)) + { + components(c).update_tag(component::Ignored); + } } @@ -144,4 +139,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_FILTER_SEPARATORS_VERT_IN_BORDERS_HH +#endif // ! SCRIBO_FILTER_OBJECTS_IN_BORDERS_HH -- 1.7.2.5