27 #ifndef MLN_LABELING_FILL_HOLES_HH
28 # define MLN_LABELING_FILL_HOLES_HH
34 # include <mln/labeling/background.hh>
35 # include <mln/labeling/compute.hh>
37 # include <mln/data/transform.hh>
39 # include <mln/core/image/dmorph/image_if.hh>
40 # include <mln/accu/math/count.hh>
62 template <
typename I,
typename N,
typename L>
64 fill_holes(const Image<I>& input, const Neighborhood<N>& nbh,
68 # ifndef MLN_INCLUDE_ONLY
70 template <
typename I,
typename N,
typename L>
73 fill_holes(const Image<I>& input, const Neighborhood<N>& nbh,
76 mln_trace(
"labeling::fill_holes");
78 mlc_equal(mln_trait_image_kind(I),
79 mln::trait::image::kind::binary)::check();
80 mln_precondition(
exact(input).is_valid());
81 mln_precondition(
exact(nbh).is_valid());
85 accu::math::count<mln_value(I)> a_;
86 util::array<
unsigned> arr =
labeling::
compute(a_, input, lbls, nlabels);
88 unsigned bg_count = 0;
92 for (
unsigned i = 1; i < arr.nelements(); ++i)
94 if (arr[i] > bg_count)
101 util::array<bool> bg_relbl(arr.nelements(),
true);
102 bg_relbl(bg_lbl) =
false;
103 mln_ch_value(I,
bool) output =
data::
transform(lbls, bg_relbl);
108 # endif // ! MLN_INCLUDE_ONLY
115 #endif // ! MLN_LABELING_FILL_HOLES_HH