/* Last edited on 2010-06-06 14:53:07 by stolfi */ /* ---------------------------------------------------------------------- */ /* ift.h, ift.c */ struct ift_node_t *prev; /* Prev node in bucket list. */ struct ift_node_t *next; /* Next node in bucket list. */ /* Clear out the queue links, just in case: */ pg->prev = NULL; pg->next = NULL; /* ---------------------------------------------------------------------- */ /* ift_functions.h */ /* PATH COST FUNCTIONS */ PathCost pf_maxval(PixelNode *s, RelArc *a, PixelNode *t, ImageGraph *G, int stage); /* For grayscale, the path cost is the maximum intensity among all pixels the path, including `t'. In particular, when `s == a == NULL' (trivial path) returns the intensity of `t' as the handicap cost. For an `N'-channel image, each pixel is first reduced to its L_1 modulus, then scaled by `1/N'. When the seeds are the local minima, the IFT of this path-cost function is the watershed transform. */ PathCost pf_sumval(PixelNode *s, RelArc *a, PixelNode *t, ImageGraph *G, int stage); /* For grayscale, the path cost is the sum of the intensities among all pixels the path, including `t'. In particular, when `s == a == NULL' (trivial path) returns the intensity of `t' as the handicap cost. For an `N'-channel image, each pixel is first reduced to its L_1 modulus, then scaled by `1/N'. When the intensity is inversely proportional to the (isotropic) local travel speed, the IFT is the minimum-time Voronoi diagram. */ PathCost pf_maxdiff(PixelNode *s, RelArc *a, PixelNode *t, ImageGraph *G, int stage); /* For an `N'-channel image, the arc cost is the L_1 distance between pixel values, scaled by `1/(N*len)' where `len' is the Euclidean length of the arc `a'. (For grayscale, this reduces to absolute difference between pixel values, divided by `len'.) In either case, the path cost is the maximum of all arc costs. When `s == a == NULL' returns an handicap cost of zero. */ PathCost pf_sumdiff(PixelNode *s, RelArc *a, PixelNode *t, ImageGraph *G, int stage); /* For an N-channel image, the arc cost is the L_1 distance between pixel values, scaled by 1/N. (For grayscale, this reduces to absolute difference between pixel values.) In either case, the path cost is the sum of all arc costs. */ PathCost pf_monoroot(PixelNode *s, RelArc *a, PixelNode *t, ImageGraph *G, int stage); /* For grayscale, the path cost is the intensity of `t' if the pixel intensities are non-decreasing along the path; else it is +oo. In particular, when `s == a == NULL' (trivial path) returns the pixel value at `t' as the handicap cost. For an `N'-channel image, each pixel is first reduced to its L_1 modulus, then scaled by `1/N'. When the seeds are all pixels, the roots of the IFT transform are all the local minima (FIFO queue policy) or one representative pixel from each local minimum (LIFO policy). */ PathCost pf_fuzzconn(PixelNode *s, RelArc *a, PixelNode *t, ImageGraph *G, int stage); /* To be implemented. */ /* AUXILIARY FUNCTIONS */ PathCost arc_cost_quantize(double x); /* Scales, discretizes, and clips `x' from `[0 _ 1]' to `[0.. MAX_FINITE_ARC_COST]'. The result is always an exact integer. Useful for many path-cost functions. */ /* ---------------------------------------------------------------------- */ /* ift.c */ void ift_error(char *file, int line, char *msg) { fprintf(stderr, "%s:%d: %s\n", file, line, msg); exit(1); } void ift_set_all_seed_labels(ImageGraph *G, SeedLabel L) { int32_t i; uint64_t LL = L; /* To supress a bogus "always false" gcc warning. */ if (LL > MAX_LABEL) { IFT_ERROR("bad L"); } for (i = 0; i < G->nodes; i++) { PixelNode *pg = &(G->node[i]); pg->L = L; } } void ift_set_seed_label(ImageGraph *G, PixelIndex col, PixelIndex row, SeedLabel L) { PixelNode *pg = ift_get_pixel_node(G, col, row); uint64_t LL = L; /* To supress a bogus "always false" gcc warning. */ if (LL > MAX_LABEL) { IFT_ERROR("bad L"); } pg->L = L; } PathCost pf_fuzzconn(PixelNode *s, RelArc *a, PixelNode *t, ImageGraph *G, int stage) { PathCost tC_new = 0; demand(FALSE, "not implemented yet"); return tC_new; } /* AUXILIARY FUNCTIONS */ PathCost arc_cost_quantize(double x) { PathCost y; if (x == INFINITY) { return INFINITE_ARC_COST; } if (x > 1.0) { demand(FALSE, "raw arc cost > 1.0"); } if (x < 0.0) { demand(FALSE, "raw arc cost < 0.0"); } y = floor(x * ((double)MAX_FINITE_ARC_COST) + 0.9999); return y; } double abs_pixel_diff(PixelValue *p, PixelValue *q, int channels) { int k; double s = 0; for(k = 0; k < channels; k++) { s += fabs(p->c[k] - q->c[k]); } return s; } double abs_pixel_value(PixelValue *p, int channels) { int k; double s = 0; for(k = 0; k < channels; k++) { s += fabs(p->c[k]); } return s; }