
* scribo/filter/objects_large.hh: Add an overload. * scribo/filter/objects_small.hh: Fix undefined variable. * scribo/fun/v2b/objects_large_filter.hh, * scribo/fun/v2b/objects_small_filter.hh: Correctly count the non filtered object. --- scribo/ChangeLog | 12 ++++++ scribo/scribo/filter/objects_large.hh | 46 +++++++++++++++++++++++++ scribo/scribo/filter/objects_small.hh | 7 ++-- scribo/scribo/fun/v2b/objects_large_filter.hh | 15 ++++++-- scribo/scribo/fun/v2b/objects_small_filter.hh | 19 +++++++--- 5 files changed, 87 insertions(+), 12 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 5660dc5..54d8d47 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,3 +1,15 @@ +2010-10-26 Guillaume Lazzara <z@lrde.epita.fr> + + Fix objects filtering routines. + + * scribo/filter/objects_large.hh: Add an overload. + + * scribo/filter/objects_small.hh: Fix undefined variable. + + * scribo/fun/v2b/objects_large_filter.hh, + * scribo/fun/v2b/objects_small_filter.hh: Correctly count the non + filtered object. + 2010-08-31 Guillaume Lazzara <z@lrde.epita.fr> Change return value for background in filtering functions. diff --git a/scribo/scribo/filter/objects_large.hh b/scribo/scribo/filter/objects_large.hh index 81986e4..8dfec9d 100644 --- a/scribo/scribo/filter/objects_large.hh +++ b/scribo/scribo/filter/objects_large.hh @@ -72,10 +72,56 @@ namespace scribo const V& label_type, unsigned max_size); + /// 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> + inline + component_set<L> + components_large(const component_set<L>& components, + unsigned max_size); + # ifndef MLN_INCLUDE_ONLY + + template <typename I, typename N, typename V> + inline + mln_concrete(I) + components_large(const Image<I>& input_, + const Neighborhood<N>& nbh_, + V& nlabels, + unsigned min_size) + { + trace::entering("scribo::filter::components_large"); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + + mln_precondition(input.is_valid()); + mln_precondition(nbh.is_valid()); + + typedef mln_ch_value(I,V) lbl_t; + component_set<lbl_t> + lbl = primitive::extract::components(input, nbh, nlabels); + + typedef fun::v2b::components_large_filter<mln_ch_value(I,V)> func_t; + func_t fv2b(lbl, min_size); + mln_concrete(I) + output = mln::data::transform(lbl.labeled_image(), fv2b); + nlabels = fv2b.nlabels_; + + trace::exiting("scribo::filter::components_large"); + return output; + } + + + template <typename L> inline component_set<L> diff --git a/scribo/scribo/filter/objects_small.hh b/scribo/scribo/filter/objects_small.hh index 1520f7d..c18c86f 100644 --- a/scribo/scribo/filter/objects_small.hh +++ b/scribo/scribo/filter/objects_small.hh @@ -70,7 +70,7 @@ namespace scribo mln_concrete(I) components_small(const Image<I>& input_, const Neighborhood<N>& nbh_, - const V& label_type, + V& nlabels, unsigned min_size); @@ -79,7 +79,8 @@ namespace scribo /// \param[in] components An object image. /// \param[in] min_size The minimum cardinality of an object. /// - /// \return An object image without small components. + /// \return A component set with small components set to + /// component::Ignored. template <typename L> component_set<L> components_small(const component_set<L>& components, @@ -104,9 +105,7 @@ namespace scribo mln_precondition(input.is_valid()); mln_precondition(nbh.is_valid()); - (void) label_type; - V nlabels; typedef mln_ch_value(I,V) lbl_t; component_set<lbl_t> lbl = primitive::extract::components(input, nbh, nlabels); diff --git a/scribo/scribo/fun/v2b/objects_large_filter.hh b/scribo/scribo/fun/v2b/objects_large_filter.hh index 91da10d..bb41850 100644 --- a/scribo/scribo/fun/v2b/objects_large_filter.hh +++ b/scribo/scribo/fun/v2b/objects_large_filter.hh @@ -88,7 +88,10 @@ namespace scribo const component_set<L> components_; /// The number of labels remaining after filtering. - mln_value(L) nlabels_; + mutable mln_value(L) nlabels_; + + /// Has already been taken into account. + mutable util::array<bool> marked_; }; @@ -102,7 +105,8 @@ namespace scribo components_large_filter<L>::components_large_filter( const component_set<L>& components, unsigned max_size) - : max_size_(max_size), components_(components) + : max_size_(max_size), components_(components), nlabels_(0), + marked_(mln::value::next(components.nelements()), false) { } @@ -117,9 +121,14 @@ namespace scribo return false; if (components_.info(l).card() <= max_size_) { - ++nlabels_; + if (!marked_(l)) + { + nlabels_ = value::next(nlabels_); + marked_(l) = true; + } return true; } + return false; } diff --git a/scribo/scribo/fun/v2b/objects_small_filter.hh b/scribo/scribo/fun/v2b/objects_small_filter.hh index 86d9287..0eda4cd 100644 --- a/scribo/scribo/fun/v2b/objects_small_filter.hh +++ b/scribo/scribo/fun/v2b/objects_small_filter.hh @@ -32,7 +32,6 @@ /// Remove small components in a binary image. - # include <mln/core/concept/function.hh> # include <mln/util/array.hh> @@ -41,8 +40,9 @@ # include <mln/labeling/compute.hh> -# include <scribo/core/component_set.hh> +# include <mln/value/next.hh> +# include <scribo/core/component_set.hh> namespace scribo { @@ -89,7 +89,10 @@ namespace scribo const component_set<L> components_; /// The number of labels remaining after filtering. - mln_value(L) nlabels_; + mutable mln_value(L) nlabels_; + + /// Has already been taken into account. + mutable mln::util::array<bool> marked_; }; @@ -103,7 +106,8 @@ namespace scribo components_small_filter<L>::components_small_filter( const component_set<L>& components, unsigned min_size) - : min_size_(min_size), components_(components), nlabels_(0) + : min_size_(min_size), components_(components), nlabels_(0), + marked_(mln::value::next(components.nelements()), false) { } @@ -118,9 +122,14 @@ namespace scribo return false; if (components_.info(l).card() >= min_size_) { - ++nlabels_; + if (!marked_(l)) + { + nlabels_ = value::next(nlabels_); + marked_(l) = true; + } return true; } + return false; } -- 1.5.6.5