diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c index d9ec1103..73703a46 100644 --- a/Fonderie/crapulator.c +++ b/Fonderie/crapulator.c @@ -197,7 +197,7 @@ switch (idFx) { retval = insitu_filtre3x3(image, 1); break; case 20: - retval = octotree_classif(image, 0.5, 0); + retval = octotree_classif(image, 0.500, 0); break; diff --git a/Fonderie/sfx.c b/Fonderie/sfx.c index 371e9216..d7aab102 100644 --- a/Fonderie/sfx.c +++ b/Fonderie/sfx.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../floatimg.h" @@ -21,33 +22,87 @@ extern int verbosity; /* -------------------------------------------------------------- */ /* nouveau du 27 decembre 2020, un soir de grand froid... */ -int octotree_classif(FloatImg *pimg, int notused) +int octotree_classif(FloatImg *pimg, float kdist, int notused) { int foo; -float mm[6], means[4]; +float mm[6], means[4], delta[3]; +float r, g, b, kr, kg, kb, dp, trig; +int idx, sz, n8, count; +typedef struct { + float x, y, z; + } ptc_t; +ptc_t ptc[8]; -fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused); +fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, + pimg, kdist, notused); + +#if 0 foo = fimg_meanvalues(pimg, means); if (foo) { fprintf(stderr, "oups %d in meanvalues\n", foo); return foo; } -fprintf(stderr, "means: %11f %11f %11f\n", means[0], means[1], means[2]); +fprintf(stderr, "means: %11f %11f %11f\n", + means[0], means[1], means[2]); +#endif foo = fimg_get_minmax_rgb(pimg, mm); if (foo) { fprintf(stderr, "oups %d in get minmax\n", foo); return foo; } -fimg_print_minmax(mm, __func__); +if (verbosity) fimg_print_minmax(mm, "input pic"); /* - * compute the height center points */ + * compute the 8 center points + */ +delta[0] = mm[1] - mm[0]; /* R */ +delta[1] = mm[3] - mm[2]; /* G */ +delta[2] = mm[5] - mm[4]; /* B */ +fprintf(stderr, "delta: %11.3f %11.3f %11.3f\n", + delta[0], delta[1], delta[2]); +for (idx=0; idx<8; idx++) { + kr = 0.25 * ((idx & 0x4) ? 1 : 3); + kg = 0.25 * ((idx & 0x2) ? 1 : 3); + kb = 0.25 * ((idx & 0x1) ? 1 : 3); + // fprintf(stderr, "%6d %.2f %.2f %.2f\n", idx, kr, kg, kb); + ptc[idx].x = (delta[0] * kr) + mm[0]; + ptc[idx].y = (delta[1] * kg) + mm[2]; + ptc[idx].z = (delta[2] * kb) + mm[4]; + fprintf(stderr, "%6d %.3f %.3f %.3f\n", idx, + ptc[idx].x, ptc[idx].y, ptc[idx].z); + } +sz = pimg->width * pimg->height; +fprintf(stderr, "surface image %d\n", sz); +trig = kdist * ((mm[1] + mm[3] + mm[5])/6.0); +fprintf(stderr, "trig value %f\n", trig); +count = 0; -return -1; +#define X(a,b) ( ((a)-(b)) * ((a)-(b)) ) +for (idx=0; idxR[idx]; g = pimg->G[idx]; b = pimg->B[idx]; + for (n8=0; n8<8; n8++) { + dp = sqrt(X(r,ptc[n8].x) + X(g,ptc[n8].y) + X(b,ptc[n8].z) ); + if (dp < trig) { + pimg->R[idx] = ptc[n8].x; + pimg->G[idx] = ptc[n8].y; + pimg->B[idx] = ptc[n8].z; + count++; + break; + } + else { + pimg->R[idx]=pimg->G[idx]=pimg->B[idx]=0.0; + } + } + } + +fprintf(stderr, "found %d pixels ok\n", count); + +return 0; } /* -------------------------------------------------------------- */ /* nouveau du 19 decembre 2020, pour le grand ecran de da Scritch */