
* scribo/fun/v2b/objects_on_border_filter.hh, * scribo/filter/objects_on_border.hh: New. --- scribo/ChangeLog | 7 ++ ..._links_bbox_h_ratio.hh => objects_on_border.hh} | 69 +++++++++++--------- ...large_filter.hh => objects_on_border_filter.hh} | 54 ++++++--------- 3 files changed, 65 insertions(+), 65 deletions(-) copy scribo/scribo/filter/{object_links_bbox_h_ratio.hh => objects_on_border.hh} (53%) copy scribo/scribo/fun/v2b/{objects_large_filter.hh => objects_on_border_filter.hh} (69%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index df242f1..f53ea42 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,12 @@ 2011-05-16 Guillaume Lazzara <lazzara@fidji.lrde.epita.fr> + New object filter. + + * scribo/fun/v2b/objects_on_border_filter.hh, + * scribo/filter/objects_on_border.hh: New. + +2011-05-16 Guillaume Lazzara <lazzara@fidji.lrde.epita.fr> + Various small fixes in Scribo. * scribo/core/document.hh: Store binary image without separators. diff --git a/scribo/scribo/filter/object_links_bbox_h_ratio.hh b/scribo/scribo/filter/objects_on_border.hh similarity index 53% copy from scribo/scribo/filter/object_links_bbox_h_ratio.hh copy to scribo/scribo/filter/objects_on_border.hh index 5573f16..d6c4cf5 100644 --- a/scribo/scribo/filter/object_links_bbox_h_ratio.hh +++ b/scribo/scribo/filter/objects_on_border.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,23 +23,28 @@ // 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 +#ifndef SCRIBO_FILTER_COMPONENTS_ON_BORDER_HH +# define SCRIBO_FILTER_COMPONENTS_ON_BORDER_HH /// \file /// -/// Invalidate links between two objects with too different height. -/// -/// \todo rename to object_links_bbox_v_ratio (v for vertical) to be -/// consistent with other routine names. +/// Remove large objects in a binary image. + + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/neighborhood.hh> +# include <mln/core/concept/function.hh> +# include <mln/labeling/compute.hh> +# include <mln/accu/math/count.hh> # include <mln/util/array.hh> -# include <scribo/core/macros.hh> -# include <scribo/core/object_links.hh> +# include <mln/pw/all.hh> + # include <scribo/core/component_set.hh> -# include <scribo/filter/object_links_bbox_ratio.hh> +# include <scribo/primitive/extract/components.hh> +# include <scribo/fun/v2b/objects_on_border_filter.hh> namespace scribo { @@ -49,47 +54,47 @@ namespace scribo using namespace mln; - /*! \brief Invalidate links between two components with too different - height. - - \param[in] links Link objects information. - \param[in] max_h_ratio The maximum height ratio of two linked - bounding boxes. - \result A filtered object link information. - */ + /// Remove too large components. + /// + /// \param[in] components An object image. + /// \param[in] max_size The maximum cardinality of an object. + /// + /// \return A component set with large components set to + /// component::Ignored. template <typename L> - object_links<L> - object_links_bbox_h_ratio(const object_links<L>& links, - float max_h_ratio); + inline + component_set<L> + components_on_border(const component_set<L>& components); # ifndef MLN_INCLUDE_ONLY template <typename L> - object_links<L> - object_links_bbox_h_ratio(const object_links<L>& links, - float max_h_ratio) + inline + component_set<L> + components_on_border(const component_set<L>& components) { - trace::entering("scribo::filter::object_links_bbox_h_ratio"); + trace::entering("scribo::filter::components_on_border"); - mln_precondition(links.is_valid()); + mln_precondition(components.is_valid()); - object_links<L> - output = object_links_bbox_ratio(links, 0, max_h_ratio); + fun::v2b::components_on_border_filter<L> f(components); - trace::exiting("scribo::filter::object_links_bbox_h_ratio"); + component_set<L> output = components.duplicate(); + output.update_tags(f, component::Ignored); + + trace::exiting("scribo::filter::components_on_border"); return output; } -# endif // ! MLN_INCLUDE_ONLY +# endif // ! MLN_INCLUDE_ONLY } // end of namespace scribo::filter } // end of namespace scribo - -#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BBOX_H_RATIO_HH +#endif // ! SCRIBO_FILTER_COMPONENTS_ON_BORDER_HH diff --git a/scribo/scribo/fun/v2b/objects_large_filter.hh b/scribo/scribo/fun/v2b/objects_on_border_filter.hh similarity index 69% copy from scribo/scribo/fun/v2b/objects_large_filter.hh copy to scribo/scribo/fun/v2b/objects_on_border_filter.hh index bb41850..e6f1738 100644 --- a/scribo/scribo/fun/v2b/objects_large_filter.hh +++ b/scribo/scribo/fun/v2b/objects_on_border_filter.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,8 +23,8 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_FUN_V2B_COMPONENTS_LARGE_FILTER_HH -# define SCRIBO_FUN_V2B_COMPONENTS_LARGE_FILTER_HH +#ifndef SCRIBO_FUN_V2B_COMPONENTS_ON_BORDER_FILTER_HH +# define SCRIBO_FUN_V2B_COMPONENTS_ON_BORDER_FILTER_HH /// \file /// @@ -58,8 +58,8 @@ namespace scribo /// Filter Functor. /// Return false for all components which are too large. template <typename L> - struct components_large_filter - : Function_v2b< components_large_filter<L> > + struct components_on_border_filter + : Function_v2b< components_on_border_filter<L> > { typedef accu::math::count<mln_psite(L)> card_t; @@ -68,8 +68,7 @@ namespace scribo /// \param[in] components Component bounding boxes. /// \param[in] max_size Maximum component size. // - components_large_filter(const component_set<L>& components, - unsigned max_size); + components_on_border_filter(const component_set<L>& components); /// Check if the component is large enough. @@ -81,17 +80,11 @@ namespace scribo // bool operator()(const mln_value(L)& l) const; - /// The minimum area. - unsigned max_size_; - /// The component set to filter. const component_set<L> components_; - /// The number of labels remaining after filtering. - mutable mln_value(L) nlabels_; - - /// Has already been taken into account. - mutable util::array<bool> marked_; + /// Labeled image bounding box. + const box2d& b_; }; @@ -102,11 +95,9 @@ namespace scribo template <typename L> inline - components_large_filter<L>::components_large_filter( - const component_set<L>& components, - unsigned max_size) - : max_size_(max_size), components_(components), nlabels_(0), - marked_(mln::value::next(components.nelements()), false) + components_on_border_filter<L>::components_on_border_filter( + const component_set<L>& components) + : components_(components), b_(components_.labeled_image().domain()) { } @@ -115,21 +106,18 @@ namespace scribo template <typename L> inline bool - components_large_filter<L>::operator()(const mln_value(L)& l) const + components_on_border_filter<L>::operator()(const mln_value(L)& l) const { if (l == literal::zero) return false; - if (components_.info(l).card() <= max_size_) - { - if (!marked_(l)) - { - nlabels_ = value::next(nlabels_); - marked_(l) = true; - } - return true; - } - - return false; + + if (components_(l).bbox().pmin().row() == b_.pmin().row() + || components_(l).bbox().pmax().row() == b_.pmax().row() + || components_(l).bbox().pmin().col() == b_.pmin().col() + || components_(l).bbox().pmax().col() == b_.pmax().col()) + return false; + + return true; } @@ -142,4 +130,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_FUN_V2B_COMPONENTS_LARGE_FILTER_HH +#endif // ! SCRIBO_FUN_V2B_COMPONENTS_ON_BORDER_FILTER_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara