- Timestamp:
- Apr 16, 2008, 12:09:33 AM (14 years ago)
- Location:
- research/2008-displacement
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
research/2008-displacement/Makefile
r2273 r2276 5 5 6 6 main: main.c 7 $(CC) -Wall -O3 -funroll-loops - W -Wall $^ -o $@ $$(pkg-config --cflags --libs sdl) -lSDL_image -lm7 $(CC) -Wall -O3 -funroll-loops -ffast-math -W -Wall $^ -o $@ $$(pkg-config --cflags --libs sdl) -lSDL_image -lm 8 8 9 9 paper.pdf: paper.tex fs-histo.tex -
research/2008-displacement/main.c
r2275 r2276 16 16 #define false 0 17 17 18 int WIDTH, HEIGHT;19 20 static inline float get(float *src, int x, int y)18 static int WIDTH, HEIGHT; 19 20 static inline float get(float const *src, int x, int y) 21 21 { 22 22 return src[y * WIDTH + x]; … … 33 33 } 34 34 35 static float *copy(float *src)35 static float *copy(float const *src) 36 36 { 37 37 float *dest = malloc(WIDTH * HEIGHT * sizeof(float)); … … 64 64 } 65 65 66 static float *gauss(float *src, float mat[NN][NN])66 static float *gauss(float const *src, float mat[NN][NN]) 67 67 { 68 68 float *dest = new(); … … 84 84 } 85 85 86 static float *fullgauss(float *src, float mat[NN][NN])86 static float *fullgauss(float const *src, float mat[NN][NN]) 87 87 { 88 88 float *dest = new(); … … 106 106 } 107 107 108 static float fulldist(float *p1,float *p2)108 static float fulldist(float const *p1, const float *p2) 109 109 { 110 110 float error = 0.; … … 121 121 } 122 122 123 static float dist(float *p1, float *p2)123 static float dist(float const *p1, float const *p2, float max) 124 124 { 125 125 float error = 0.; 126 126 int x, y; 127 127 128 max *= (WIDTH - N) * (HEIGHT - N); 129 128 130 for(y = N; y < HEIGHT - N; y++) 131 { 129 132 for(x = N; x < WIDTH - N; x++) 130 133 { … … 133 136 } 134 137 138 /* Experience shows that this is almost useless, because the 139 * functions we manipulate are so small that the difference 140 * only happens in the last 1% of the image... */ 141 if(error > max) 142 break; 143 } 144 135 145 return error / ((WIDTH - N) * (HEIGHT - N)); 136 146 } 137 147 138 static float *load(char *name)148 static float *load(char const *name) 139 149 { 140 150 SDL_Surface *tmp, *surface; … … 169 179 } 170 180 171 static void save(float *src, char*name)181 static void save(float const *src, char const *name) 172 182 { 173 183 SDL_Surface *surface; … … 190 200 } 191 201 192 static float *ostromoukhov(float *src)202 static float *ostromoukhov(float const *src) 193 203 { 194 204 static int const table[][3] = … … 276 286 h i j k l 277 287 */ 278 static float *ed(float *src, int serpentine,288 static float *ed(float const *src, int serpentine, 279 289 int a, int b, int c, int d, int e, int f, 280 290 int g, int h, int i, int j, int k, int l) … … 357 367 358 368 /* XXX */ 359 static float *dbs(float *src, float *orig, float sigma, float dx, float dy) 369 static float *dbs(float const *src, float const *orig, 370 float sigma, float dx, float dy) 360 371 { 361 372 float mat[NN][NN]; … … 370 381 tmp2 = fullgauss(dest, mat); 371 382 372 error = dist(tmp, tmp2 );383 error = dist(tmp, tmp2, 1.); 373 384 374 385 for(;;) … … 498 509 } 499 510 500 static void study(float *src, float *dest, float sigma, float precision) 511 static void study(float const *src, float const *dest, 512 float sigma, float precision) 501 513 { 502 514 # define Z 3 503 515 float mat[NN][NN]; 504 516 float *tmp, *tmp2; 505 float e 0, best = 0., fx = -1., fy = -1., step = 2.;517 float e, e0, best = 1., fx = -1., fy = -1., step = 2., bfx = 0., bfy = 0.; 506 518 int dx, dy; 507 519 … … 510 522 tmp2 = gauss(dest, mat); 511 523 512 e0 = dist(tmp, tmp2 );524 e0 = dist(tmp, tmp2, 1.); 513 525 free(tmp2); 514 526 515 527 while(step > precision) 516 528 { 517 float bfx = 0., bfy = 0., e;518 519 best = 9999.;520 521 529 for(dy = 0; dy <= Z; dy++) 522 530 for(dx = 0; dx <= Z; dx++) … … 524 532 makegauss(mat, sigma, fx + step * dx / Z, fy + step * dy / Z); 525 533 tmp2 = gauss(dest, mat); 526 e = dist(tmp, tmp2 );534 e = dist(tmp, tmp2, best); 527 535 free(tmp2); 528 536 if(e < best) … … 546 554 } 547 555 548 static float *merge(float *im1, float *im2, float t)556 static float *merge(float const *im1, float const *im2, float t) 549 557 { 550 558 float *dest = new(); … … 570 578 int main(int argc, char *argv[]) 571 579 { 572 float mat0[NN][NN];573 float mat[NN][NN];574 580 float *src; 575 float sigma; 576 int mode, dx, dy, i; 581 int mode, i; 577 582 578 583 if(argc < 2) … … 631 636 case 4: 632 637 { 638 float mat0[NN][NN]; 633 639 float *dest, *tmp, *tmp2; 634 640 int a, b, c, d, e; … … 671 677 tmp = gauss(src, mat0); 672 678 tmp2 = gauss(dest, mat0); 673 printf("E = %.5g\n", 1000. * dist(tmp, tmp2 ));679 printf("E = %.5g\n", 1000. * dist(tmp, tmp2, 1.)); 674 680 free(tmp); 675 681 free(tmp2); 676 682 } 677 683 else 678 study(src, dest, 1.2, 0.0 1);684 study(src, dest, 1.2, 0.001); 679 685 fflush(stdout); 680 686 free(dest); … … 729 735 makegauss(mat, 1.2, fx, fy); 730 736 tmp2 = gauss(dest, mat); 731 printf("%g %g %g\n", fy, fx, 1000. * dist(tmp, tmp2 ));737 printf("%g %g %g\n", fy, fx, 1000. * dist(tmp, tmp2, 1.)); 732 738 fflush(stdout); 733 739 free(tmp2); … … 751 757 tmp2 = gauss(dest, 0., 0.); 752 758 printf("%.5g: (%02d %02d %02d %02d)\n", 753 1000. * dist(tmp, tmp2 ), a, b, c, d);759 1000. * dist(tmp, tmp2, 1.), a, b, c, d); 754 760 free(dest); 755 761 free(tmp2); … … 766 772 dest = ed(src, false, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0); 767 773 tmp2 = gauss(dest, mat0); 768 printf("%.5g ", 1000. * dist(tmp, tmp2 ));774 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 769 775 free(tmp2); 770 776 makegauss(mat, 1.2, 0.16, 0.28); 771 777 tmp2 = gauss(dest, mat); 772 printf("%.5g ", 1000. * dist(tmp, tmp2 ));778 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 773 779 free(tmp2); 774 780 free(dest); … … 776 782 dest = ed(src, false, 7, 5, 3, 5, 7, 5, 3, 1, 3, 5, 3, 1); 777 783 tmp2 = gauss(dest, mat0); 778 printf("%.5g ", 1000. * dist(tmp, tmp2 ));784 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 779 785 free(tmp2); 780 786 makegauss(mat, 1.2, 0.26, 0.76); 781 787 tmp2 = gauss(dest, mat); 782 printf("%.5g ", 1000. * dist(tmp, tmp2 ));788 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 783 789 free(tmp2); 784 790 free(dest); … … 786 792 dest = ostromoukhov(src); 787 793 tmp2 = gauss(dest, mat0); 788 printf("%.5g ", 1000. * dist(tmp, tmp2 ));794 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 789 795 free(tmp2); 790 796 makegauss(mat, 1.2, 0.0, 0.19); 791 797 tmp2 = gauss(dest, mat); 792 printf("%.5g ", 1000. * dist(tmp, tmp2 ));798 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 793 799 free(tmp2); 794 800 free(dest); … … 796 802 dest = ed(src, true, 2911, 0, 0, 1373, 3457, 2258, 0, 0, 0, 0, 0, 0); 797 803 tmp2 = gauss(dest, mat0); 798 printf("%.5g ", 1000. * dist(tmp, tmp2 ));804 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 799 805 free(tmp2); 800 806 makegauss(mat, 1.2, 0.0, 0.34); 801 807 tmp2 = gauss(dest, mat); 802 printf("%.5g ", 1000. * dist(tmp, tmp2 ));808 printf("%.5g ", 1000. * dist(tmp, tmp2, 1.)); 803 809 free(tmp2); 804 810 free(dest);
Note: See TracChangeset
for help on using the changeset viewer.