Explorar el Código

* Implemented a few study modes:

1. study displacement on progressive blends of 2 images
     2. exhaustive ED kernel optimisation using standard HVS gaussian distance
     3. exhaustive ED kernel optimisation using off-center gaussian distance


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/research@2274 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam hace 16 años
padre
commit
bb54dedbb9
Se han modificado 1 ficheros con 110 adiciones y 51 borrados
  1. +110
    -51
      2008-displacement/main.c

+ 110
- 51
2008-displacement/main.c Ver fichero

@@ -502,7 +502,7 @@ static void study(float *src, float *dest, float sigma, float precision)
# define Z 3
float mat[NN][NN];
float *tmp, *tmp2;
float e0, best, fx = -1., fy = -1., step = 2.;
float e0, best = 0., fx = -1., fy = -1., step = 2.;
int dx, dy;

makegauss(mat, sigma, 0., 0.);
@@ -540,7 +540,8 @@ static void study(float *src, float *dest, float sigma, float precision)

free(tmp);

printf("%g -> %g for %g %g\n", 1000 * e0, 1000 * best, fx, fy);
printf("E = %g E_min = %g dx = %g dy = %g\n",
1000 * e0, 1000 * best, fx, fy);
fflush(stdout);
}

@@ -556,39 +557,122 @@ static float *merge(float *im1, float *im2, float t)
return dest;
}

static void usage(char *argv[])
{
fprintf(stderr, "Usage: %s <mode> [ARGS...]\n", argv[0]);
fprintf(stderr, "Allowed modes:\n");
fprintf(stderr, " -1 <src1> <src2> raster FS displacement study on blends of src1 and src2\n");
fprintf(stderr, " -2 <src> quick (a,b,c,d) ED kernel analysis on src\n");
fprintf(stderr, " -3 <src> exhaustive (a,b,c,d) ED kernel analysis on src\n");
}

int main(int argc, char *argv[])
{
float mat0[NN][NN];
float mat[NN][NN];
float *src, *src2, *dest, *tmp, *tmp2;
float *src;
float sigma;
int dx, dy, a, b, c, d, i;
int mode, dx, dy, i;

if(argc < 2)
return 1;
{
fprintf(stderr, "%s: too few arguments\n", argv[0]);
usage(argv);
return EXIT_FAILURE;
}

if(argv[1][0] != '-' || !(mode = atoi(argv[1] + 1)))
{
fprintf(stderr, "%s: invalid mode `%s'\n", argv[0], argv[1]);
usage(argv);
return EXIT_FAILURE;
}

src = load(argv[1]);
src = load(argv[2]);
if(!src)
return 2;

#if 0
if(argc < 3)
return 3;
src2 = load(argv[2]);
if(!src2)
return 4;

for(i = 0; i <= 100; i++)
switch(mode)
{
tmp = merge(src, src2, (float)i / 100.);
dest = ed(tmp, 7, 0, 1, 3, 5, 0, 0, 0, 0, 0, 0, 0);
study(tmp, dest, 1.2, 0.001);
free(dest);
free(tmp);
}
free(src2);
free(src);
case 1:
{
float *src2, *dest, *tmp;

if(argc < 3)
return 3;
src2 = load(argv[2]);
if(!src2)
return 4;

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);
free(dest);
free(tmp);
}
free(src2);
free(src);
}
break;

case 2:
case 3:
{
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++)
{
if(a + b + c + d + e != 16)
continue;

/* Slightly shuffle our coefficients to avoid waiting until
* 75% progress before having an idea of what's going on. */
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);

#if 0
if(b2 > c2) continue;
if(d2 > c2) continue;
if(d2 > a2) continue;
#endif
/* We only want 4-cell kernels for now */
if(b2) continue;
//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 == 2)
{
tmp = gauss(src, mat0);
tmp2 = gauss(dest, mat0);
printf("E = %.5g\n", 1000. * dist(tmp, tmp2));
free(tmp);
free(tmp2);
}
else
study(src, dest, 1.2, 0.01);
fflush(stdout);
free(dest);
}

free(src);
}
break;

#if 0
tmp = ed(src, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
@@ -644,35 +728,6 @@ int main(int argc, char *argv[])
save(dest, "output.bmp");
#endif

#if 0
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++)
{
float *tmp;
if(a + b + c + d != 16)
continue;
#if 0
if(b > c) continue;
if(d > c) continue;
if(d > a) continue;
#endif
printf("%02d %02d %02d %02d: ", a, b, c, d);
dest = ed(src, true, a, 0, 0, b, c, d, 0, 0, 0, 0, 0, 0);
//dest = ed(src, false, a, 0, 0, b, c, d, 0, 0, 0, 0, 0, 0);
//study(src, dest, 1.2, 0.01);
tmp = gauss(src, mat0);
tmp2 = gauss(dest, mat0);
printf("%.5g\n", 1000. * dist(tmp, tmp2));
fflush(stdout);
free(tmp);
free(tmp2);
free(dest);
}
#endif

#if 0
tmp = gauss(src, 0., 0.);
for(a = 0; a < 16; a++)
@@ -776,6 +831,9 @@ int main(int argc, char *argv[])
}
#endif

}

#if 0
tmp = new();
a = 0;
for(sigma = 0.8; sigma < 2; sigma *= 1.03)
@@ -786,6 +844,7 @@ int main(int argc, char *argv[])
sprintf(buf, "output-dbs-%i.bmp", a++);
save(dest, buf);
}
#endif

return 0;
}


Cargando…
Cancelar
Guardar