diff --git a/2008-displacement/main.c b/2008-displacement/main.c index 9a0c5be..3d1ffb1 100644 --- a/2008-displacement/main.c +++ b/2008-displacement/main.c @@ -511,21 +511,27 @@ static float *dbs(float const *src, float const *orig, } static void study(float const *src, float const *dest, - float sigma, float precision) + float sigma, float precision, float fdx, float fdy) { # define Z 3 - float mat[NN][NN]; + float mat[NN][NN], mat2[NN][NN]; float *tmp, *tmp2; - float e, e0, best = 1., fx = -1., fy = -1., step = 2., bfx = 0., bfy = 0.; + float e, e0, e1; + float best = 1., fx = -1., fy = -1., step = 2., bfx = 0., bfy = 0.; int dx, dy; makegauss(mat, sigma, 0., 0.); tmp = gauss(src, mat); - tmp2 = gauss(dest, mat); + tmp2 = gauss(dest, mat); e0 = dist(tmp, tmp2, 1.); free(tmp2); + makegauss(mat2, sigma, fdx, fdy); + tmp2 = gauss(dest, mat2); + e1 = dist(tmp, tmp2, 1.); + free(tmp2); + while(step > precision) { for(dy = 0; dy <= Z; dy++) @@ -550,8 +556,8 @@ static void study(float const *src, float const *dest, free(tmp); - printf("E = %g E_min = %g dx = %g dy = %g\n", - 1000 * e0, 1000 * best, fx, fy); + printf("E = %g E_fast = %g E_min = %g dx = %g dy = %g\n", + 1000. * e0, 1000. * e1, 1000. * best, fx, fy); fflush(stdout); } @@ -575,6 +581,7 @@ static void usage(char *argv[]) fprintf(stderr, " -2 raster FS displacement study on blends of src1 and src2\n"); fprintf(stderr, " -3 quick (a,b,c,d) ED kernel analysis on src\n"); fprintf(stderr, " -4 exhaustive (a,b,c,d) ED kernel analysis on src\n"); + fprintf(stderr, " -5 exhaustive displacement study on src\n"); } int main(int argc, char *argv[]) @@ -600,12 +607,16 @@ int main(int argc, char *argv[]) if(!src) return 2; + printf("### mode %i on `%s' ###\n", mode, argv[2]); + switch(mode) { case 1: { - float *dest = ed(src, false, 7, 0, 1, 3, 5, 0, 0, 0, 0, 0, 0, 0); - study(src, dest, 1.2, 0.001); + float *dest = ed(src, false, 7, 0, + 0, 3, 5, 1, 0, + 0, 0, 0, 0, 0); + study(src, dest, 1.2, 0.001, .16, .28); free(dest); free(src); } @@ -624,8 +635,10 @@ int main(int argc, char *argv[]) for(i = 0; i <= 100; i++) { tmp = merge(src, src2, (float)i / 100.); - dest = ed(tmp, false, 7, 0, 1, 3, 5, 0, 0, 0, 0, 0, 0, 0); - study(tmp, dest, 1.2, 0.001); + dest = ed(tmp, false, 7, 0, + 0, 3, 5, 1, 0, + 0, 0, 0, 0, 0); + study(tmp, dest, 1.2, 0.001, .16, .28); free(dest); free(tmp); } @@ -637,18 +650,19 @@ int main(int argc, char *argv[]) case 3: case 4: { - float mat0[NN][NN]; + float mat[NN][NN]; float *dest, *tmp, *tmp2; int a, b, c, d, e; - makegauss(mat0, 1.2, 0, 0); - for(a = 0; a <= 16; a++) - for(b = 0; b <= 16; b++) - for(c = 0; c <= 16; c++) - for(d = 0; d <= 16; d++) - for(e = 0; e <= 16; e++) +#define TOTAL 16 + makegauss(mat, 1.2, 0, 0); + for(a = 0; a <= TOTAL; a++) + for(b = 0; b <= TOTAL; b++) + for(c = 0; c <= TOTAL; c++) + for(d = 0; d <= TOTAL; d++) + for(e = 0; e <= TOTAL; e++) { - if(a + b + c + d + e != 16) + if(a + b + c + d + e != TOTAL) continue; /* Slightly shuffle our coefficients to avoid waiting until @@ -656,12 +670,12 @@ int main(int argc, char *argv[]) int a2 = a, b2 = b, c2 = c, d2 = d, e2 = e; #define SHUFFLE(p,q,n) \ if(p+q) { int tmp = p+q; p = (p+n) % (tmp+1); q = tmp-p; } - SHUFFLE(c2, d2, 7); SHUFFLE(b2, d2, 5); - SHUFFLE(a2, d2, 3); SHUFFLE(b2, c2, 2); - SHUFFLE(a2, e2, 3); SHUFFLE(b2, e2, 2); - SHUFFLE(a2, c2, 4); SHUFFLE(a2, b2, 6); - SHUFFLE(c2, e2, 9); SHUFFLE(d2, e2, 7); - SHUFFLE(a2, d2, 9); SHUFFLE(a2, b2, 7); + SHUFFLE(c2, d2, 777); SHUFFLE(b2, d2, 555); + SHUFFLE(a2, d2, 333); SHUFFLE(b2, c2, 222); + SHUFFLE(a2, e2, 333); SHUFFLE(b2, e2, 222); + SHUFFLE(a2, c2, 444); SHUFFLE(a2, b2, 666); + SHUFFLE(c2, e2, 999); SHUFFLE(d2, e2, 777); + SHUFFLE(a2, d2, 999); SHUFFLE(a2, b2, 777); #if 0 if(b2 > c2) continue; @@ -673,17 +687,21 @@ int main(int argc, char *argv[]) //printf("K = %d,%d,%d,%d,%d ", a2, b2, c2, d2, e2); printf("K = %d,%d,%d,%d ", a2, c2, d2, e2); - dest = ed(src, false, a2, 0, b2, c2, d2, e2, 0, 0, 0, 0, 0, 0); - if(mode == 3) + dest = ed(src, false, a2, 0, + b2, c2, d2, e2, 0, + 0, 0, 0, 0, 0); + if(mode == 4) { - tmp = gauss(src, mat0); - tmp2 = gauss(dest, mat0); + study(src, dest, 1.2, 0.001, 0., 0.); + } + else + { + tmp = gauss(src, mat); + tmp2 = gauss(dest, mat); printf("E = %.5g\n", 1000. * dist(tmp, tmp2, 1.)); free(tmp); free(tmp2); } - else - study(src, dest, 1.2, 0.001); fflush(stdout); free(dest); } @@ -692,6 +710,33 @@ int main(int argc, char *argv[]) } break; + case 5: + { + float *dest; + + dest = ed(src, false, 7, 0, + 0, 3, 5, 1, 0, + 0, 0, 0, 0, 0); + study(src, dest, 1.2, 0.001, .16, .28); + free(dest); + + dest = ed(src, false, 7, 5, + 3, 5, 7, 5, 3, + 1, 3, 5, 3, 1); + study(src, dest, 1.2, 0.001, .26, .76); + free(dest); + + dest = ostromoukhov(src); + study(src, dest, 1.2, 0.001, .0, .19); + free(dest); + + dest = ed(src, true, 2911, 0, + 0, 1373, 3457, 2258, 0, + 0, 0, 0, 0, 0); + study(src, dest, 1.2, 0.001, .0, .34); + } + break; + #if 0 tmp = ed(src, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0); //dest = dbs(src, tmp, 0., 0.); @@ -766,54 +811,6 @@ int main(int argc, char *argv[]) save(dest, "output.bmp"); #endif -#if 0 - printf("%s: ", argv[1]); - makegauss(mat0, 1.2, 0, 0); - tmp = gauss(src, mat0); - - dest = ed(src, false, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0); - tmp2 = gauss(dest, mat0); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - makegauss(mat, 1.2, 0.16, 0.28); - tmp2 = gauss(dest, mat); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - free(dest); - - dest = ed(src, false, 7, 5, 3, 5, 7, 5, 3, 1, 3, 5, 3, 1); - tmp2 = gauss(dest, mat0); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - makegauss(mat, 1.2, 0.26, 0.76); - tmp2 = gauss(dest, mat); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - free(dest); - - dest = ostromoukhov(src); - tmp2 = gauss(dest, mat0); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - makegauss(mat, 1.2, 0.0, 0.19); - tmp2 = gauss(dest, mat); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - free(dest); - - dest = ed(src, true, 2911, 0, 0, 1373, 3457, 2258, 0, 0, 0, 0, 0, 0); - tmp2 = gauss(dest, mat0); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - makegauss(mat, 1.2, 0.0, 0.34); - tmp2 = gauss(dest, mat); - printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); - free(tmp2); - free(dest); - - printf("\n"); -#endif - #if 0 printf("%s\n", argv[1]); diff --git a/2008-displacement/study-5.sh b/2008-displacement/study-5.sh new file mode 100755 index 0000000..0266afc --- /dev/null +++ b/2008-displacement/study-5.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +set -e + +if [ ! -x ./main ]; then + make main +fi + +if [ "$1" = "" ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ ! -d "$1" ]; then + echo "$0: $1 is not a directory" + exit 1 +fi + +OUTPUT="$(echo "$1" | tr -d /).txt" +echo "$0: outputting to $OUTPUT" + +touch "$OUTPUT" +find $1 -name '?????????????.???' | while read i; do + TMP="$(./main -5 $i)" + echo "$TMP" >> "$OUTPUT" + echo "$TMP" +done +