arrays - Implementing LSL for Connected Component Labeling/Blob Extraction -
i trying implement light speed labeling algorithm https://www.lri.fr/~lacas/publications/jrtip10.pdf. tried follow algorithmic approach described in paper closely possible (pgs 9-12) output doesn't make sense after equivalence stage.
anyone have idea problem is?
void segment(const unsigned * xi, const unsigned& n, unsigned * eri, unsigned *rlci, unsigned& ner) { unsigned x1 = 0; unsigned f = 0; unsigned er = 0; (unsigned j = 0; j < n; ++j) { const unsigned x0 = xi[j]; f = x0 ^ x1; rlci[er] = j; er = er + f; eri[j] = er; x1 = x0; } if (x1 != 0) { rlci[er] = n; } er = er + x1; ner = er; } void equivalance(const unsigned& ner, unsigned * rlci, unsigned * eq, unsigned * er0, unsigned * era0, unsigned * era1, unsigned& nea, const unsigned& n = 0) { (unsigned er = 1; er <= ner; er += 2) { int j0 = rlci[er - 1]; int j1 = rlci[er] - 1; // unnecessary given optimization , need 4-connectivity: // if (j0 > 0) j0 = j0 - 1; // if (j1 < n - 1) j1 = j1 + 1; int er0 = er0[j0]; int er1 = er0[j1]; if (!(er0 & 1)) er0 = er0 + 1; if (!(er1 & 1)) er1 = er1 - 1; if (er1 >= er0) // adjacent label { unsigned ea = era0[er0]; unsigned = eq[ea]; (unsigned erk = er0 + 2; erk <= er1; ++erk) { unsigned eak = era0[erk]; unsigned ak = eq[eak]; if (a < ak) { eq[eak] = a; } else { = ak; eq[ea] = a; ea = eak; } } era1[er] = a; } else { nea = nea + 1; era1[er] = nea; } } } typedef std::vector<unsigned> value_type; void bwlabel(const double* x, unsigned * ea, const unsigned& n, const unsigned& m) { unsigned nea = 0; const unsigned size = n * m; value_type eq(size, 0), er(size, 0), era(size, 0), a(size, 0), rlc(m * (2 * n), 0), in(x, x + size), ner(m, 0); // step 1 (int m = 0; m < m; ++m) { segment(&in[0] + n * m, n, &er[0] + n * m, &rlc[0] + m * (2 * n), ner[m]); } // step 2 (int m = 1; m < m; ++m) { equivalance(ner[m], &rlc[0] + m * (2 * n), &eq[0], &er[0] + (m - 1) * n, &era[0] + (m - 1) * n, &era[0] + m * n, nea, n); } // step 3 (int j = 0; j < size; ++j) { ea[j] = era[er[j]]; } // step 4 unsigned na = 0; (int e = 0; e < size; ++e) { if (eq[e] != e) { a[e] = eq[eq[e]]; } else { na = na + 1; a[e] = na; } } // step 5 (int j = 0; j < size; ++j) { ea[j] = a[ea[j]]; } } in= 1 1 0 1 1 0 0 1 1 1 0 1 1 0 1 0 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1 1 0 1 1 0 1 0 0 1 1 1 0 1 0 0 0 rlc= [0]0 [1]2 [2]3 [3]5 [4]7 [5]10 [6]0 [7]0 [8]0 [9]0 [0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 [0]1 [1]3 [2]4 [3]5 [4]7 [5]10 [6]0 [7]0 [8]0 [9]0 [0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 [0]0 [1]1 [2]2 [3]7 [4]8 [5]9 [6]0 [7]0 [8]0 [9]0 [0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 [0]0 [1]1 [2]5 [3]7 [4]8 [5]9 [6]0 [7]0 [8]0 [9]0 [0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 [0]2 [1]4 [2]7 [3]10 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 [0]0 [1]0 [2]0 [3]0 [4]0 [5]0 [6]0 [7]0 [8]0 [9]0 er= 1 1 2 3 3 4 4 5 5 5 0 1 1 2 3 4 4 5 5 5 1 2 3 3 3 3 3 4 5 6 1 2 2 2 2 3 3 4 5 6 0 0 1 1 2 2 2 3 3 3 0 1 1 2 2 2 3 4 5 6 1 2 3 3 3 3 3 4 4 4 1 2 3 4 5 6 6 6 7 8 0 1 1 1 1 2 3 3 4 5 0 0 1 1 1 2 3 4 4 4 era= 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 4 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eq= 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ea= 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
for starters, have omitted right border compensation variable b
. affects results of rlc.
you obtaining (for first row):
[0]0 [1]2 [2]3 [3]5 [4]7 [5]10 [6]0 [7]0 [8]0 [9]0
when should obtaining:
[0]0 [1]1 [2]3 [3]4 [4]7 [5]10 [6]0 [7]0 [8]0 [9]0
thanks.
Comments
Post a Comment