Index: work/gpstroke/Makefile =================================================================== --- work/gpstroke/Makefile (revision 7411) +++ work/gpstroke/Makefile (revision 7412) @@ -1,9 +1,12 @@ -CFLAGS = -Wall -g -O3 +CFLAGS = -Wall -g +# -O3 LDFLAGS = -lm LIBS=pcb_draw.o gp.o c24lib/image/draw.o c24lib/image/image.o c24lib/image/pnm.o -all: find_polyl find_line_indep cap +all: find_polyl find_line_indep cap erode +erode: erode.o $(LIBS) + cap: cap.o $(LIBS) find_polyl: find_polyl.o $(LIBS) Index: work/gpstroke/erode.c =================================================================== --- work/gpstroke/erode.c (nonexistent) +++ work/gpstroke/erode.c (revision 7412) @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include "c24lib/image/image.h" +#include "c24lib/image/draw.h" +#include "c24lib/image/pnm.h" + +#include "pcb_draw.h" + + +int stat[100]; + +static inline void ray(image_t *i, double x, double y, double dx, double dy, int *out) +{ + pixel_t *p; + int h = 0, xx, yy; + do { + x += dx; + y += dy; + xx = round(x); + yy = round(y); + p = &image_pix(i, xx, yy); + h++; + + } while(p->r == 0); + + if (h < *out) + *out = h; +} + +static inline int height(image_t *i, int cx, int cy) +{ + pixel_t *p; + double dx, dy; + int h = i->sx + i->sy; + p = &image_pix(i, cx, cy); + if (p->r != 0) + return 0; + for(dy = -1.0; dy <= 1.0; dy+=0.27) + for(dx = -1.0; dx <= 1.0; dx+=0.27) + ray(i, (double)cx, (double)cy, dx, dy, &h); + return h; +} + +int main(int arc, char *argv[]) +{ + image_t *ref; + int *hg; + int maxh = 0; + int x, y, n, cutoff, end; + char *ref_fn = "1.pnm"; + + if (argv[1] != NULL) + ref_fn = argv[1]; + + ref = pnm_load(ref_fn); + + hg = calloc(sizeof(int), ref->sx * ref->sy); + for(y = 1; y < ref->sy-1; y++) { + for(x = 1; x < ref->sy-1; x++) { + int h = height(ref, x, y); + if (h > maxh) + maxh = h; + stat[h]++; + printf("%d", h); + hg[x + y*ref->sx] = h; + } + printf("\n"); + } + + cutoff = 0; + for(n = 1; n <= maxh; n++) { + printf("h=%d %d\n", n, stat[n]); + if ((n > 1) && (stat[n] < stat[n-1]/2) && (cutoff == 0)) { + cutoff = n-1; + } + } + + printf("-- cutoff=%d\n", cutoff); + end = ref->sx * ref->sy; + for(n = 0; n < end; n++) { + if (hg[n] == cutoff) + ref->pixmap[n] = pixel_red; + else if (ref->pixmap[n].r != 255) { + ref->pixmap[n].r = 200; + ref->pixmap[n].g = 200; + ref->pixmap[n].b = 200; + } + } + pnm_save(ref, "OUT.pnm"); +} +