27 #ifndef SCRIBO_AFP_COMPONENTS_HH
28 # define SCRIBO_AFP_COMPONENTS_HH
34 # include <mln/io/pbm/load.hh>
35 # include <mln/io/pgm/save.hh>
37 # include <mln/extension/adjust.hh>
38 # include <mln/extension/fill.hh>
39 # include <mln/data/fill.hh>
40 # include <mln/accu/shape/bbox.hh>
42 # include <mln/core/alias/neighb2d.hh>
43 # include <mln/core/image/dmorph/image_if.hh>
44 # include <mln/pw/value.hh>
45 # include <mln/debug/println.hh>
47 # include <mln/util/timer.hh>
48 # include <mln/labeling/foreground.hh>
49 # include <mln/labeling/wrap.hh>
50 # include <mln/extension/fill.hh>
51 # include <mln/data/compare.hh>
60 unsigned my_find_root(image2d<I>&
data,
unsigned x)
62 if (data.element(x).parent == x)
65 return data.element(x).parent = my_find_root(data,
66 data.element(x).parent);
75 float row_sum, col_sum;
80 return p_max.
col() - p_min.
col();
85 return p_max.
row() - p_min.
row();
88 void init(
unsigned p,
int row,
int col)
102 r.parent = this->parent;
104 row_sum += r.row_sum;
105 col_sum += r.col_sum;
108 mln_invariant(p_min.
row() <= r.p_min.
row());
110 if (r.p_min.
col() < p_min.
col())
111 p_min.
col() = r.p_min.
col();
112 if (r.p_max.
row() > p_max.
row())
113 p_max.
row() = r.p_max.
row();
114 if (r.p_max.
col() > p_max.
col())
115 p_max.
col() = r.p_max.
col();
120 template <
typename V>
143 dp_border = 2 * input.
border();
150 util::array<int> dp = positive_offsets_wrt(input, nbh);
151 const unsigned n_nbhs = dp.nelements();
154 unsigned p = input.offset_of_point(
point2d(nrows - 1,
ncols - 1));
155 for (
int row = nrows - 1; row >= 0; --row, p -= dp_border)
156 for (
int col =
ncols - 1; col >= 0; --col, --
p)
161 data.
element(p).init(p, row, col);
163 for (
unsigned i = 0; i < n_nbhs; ++i)
165 unsigned n = p + dp[i];
168 unsigned r = my_find_root(data, n);
184 unsigned p = input.offset_of_point(
point2d(0, 0));
185 for (
int row = 0; row <
nrows; ++row, p += dp_border)
186 for (
int col = 0; col <
ncols; ++col, ++
p)
190 const info& dta = data.
element(p);
195 && dta.height() >= 1))
197 label.
element(p) = ++current_label;
200 std::make_pair(
box2d(dta.p_min, dta.p_max),
201 std::make_pair(
point2d(dta.row_sum / dta.card,
202 dta.col_sum / dta.card), dta.card)));
210 nlabels = current_label;
218 #endif // ! SCRIBO_AFP_COMPONENTS_HH