Exemplo n.º 1
0
// API
int adsf_union(int *t, int n, int a, int b)
{
    assert(a >= 0 && a < n);
    assert(b >= 0 && b < n);
    a = adsf_find(t, n, a);
    b = adsf_find(t, n, b);
    int c = a;
    if (a != b)
        c = adsf_make_link(t, a, b);
    return c;
}
Exemplo n.º 2
0
// connected components of positive pixels of the image rep
static void connected_component_filter(int *rep, int w, int h, float *in, float intensity_threshold)
{
   adsf_begin(rep, w*h);

   // remove from dsf pixels with NANs in input
   for (int i = 0; i < w*h; i++)
      if (isnan(in[i]))
	      rep[i] = -1;

   for (int j = 0; j < h - 1; j++)
      for (int i = 0; i < w - 1; i++)
      {
         int p0 = j*w + i;
         int p1 = j*w + i+1;
         int p2  = (j+1)*w + i;
         if (rep[p0] >= 0 && rep[p1] >= 0 && 
             fabs(in[p0] - in[p1]) < intensity_threshold)
            adsf_union(rep, w*h, p0, p1); 
         if (rep[p0] >= 0 && rep[p2] >= 0 && 
             fabs(in[p0] - in[p2]) < intensity_threshold)
            adsf_union(rep, w*h, p0, p2);

      }
   for (int i = 0; i < w*h; i++)
      if (rep[i] >= 0)
         rep[i] = adsf_find(rep, w*h, i);
}
Exemplo n.º 3
0
// API
int adsf_find(int *t, int n, int a) {
    assert(a >= 0 && a < n);
    if (a != t[a])
        t[a] = adsf_find(t, n, t[a]);
    return t[a];
}