Compare commits

..

3 Commits

Author SHA1 Message Date
da44439be7 cleanup 2020-12-29 13:08:19 +01:00
47e8db923b first try of octotree_classif 2020-12-29 12:56:26 +01:00
ab8ad5a913 missing parameter 2020-12-29 12:22:51 +01:00
3 changed files with 67 additions and 10 deletions

View File

@ -197,7 +197,7 @@ switch (idFx) {
retval = insitu_filtre3x3(image, 1); retval = insitu_filtre3x3(image, 1);
break; break;
case 20: case 20:
retval = octotree_classif(image, 0); retval = octotree_classif(image, 0.500, 0);
break; break;
@ -262,6 +262,7 @@ switch (num) {
case 18: return "updown"; case 18: return "updown";
case 20: return "octoclass"; case 20: return "octoclass";
case 25: return "vsglitch";
} }
return "???"; return "???";

View File

@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h> #include <malloc.h>
#include <math.h>
#include "../floatimg.h" #include "../floatimg.h"
@ -21,33 +22,88 @@ extern int verbosity;
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/* nouveau du 27 decembre 2020, un soir de grand froid... */ /* 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; 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); #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__,
pimg, kdist, notused);
#endif
#if 0
foo = fimg_meanvalues(pimg, means); foo = fimg_meanvalues(pimg, means);
if (foo) { if (foo) {
fprintf(stderr, "oups %d in meanvalues\n", foo); fprintf(stderr, "oups %d in meanvalues\n", foo);
return 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); foo = fimg_get_minmax_rgb(pimg, mm);
if (foo) { if (foo) {
fprintf(stderr, "oups %d in get minmax\n", foo); fprintf(stderr, "oups %d in get minmax\n", foo);
return 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;
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; idx<sz; idx++) {
r = pimg->R[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, "%s: %d/%d pixels, ratio %f\n", __func__, count, sz,
(float)count/(float)sz);
return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/* nouveau du 19 decembre 2020, pour le grand ecran de da Scritch */ /* nouveau du 19 decembre 2020, pour le grand ecran de da Scritch */

View File

@ -1,10 +1,10 @@
/* /*
* sfx.h - special effects for fonderie & interpolator * sfx.h - special effects for fonderie & interpolator
* ---------------------------------------------------
*/ */
int bouger_les_pixels(FloatImg *pimg, int kaboo); int bouger_les_pixels(FloatImg *pimg, int kaboo);
int octotree_classif(FloatImg *pimg, int notused); int octotree_classif(FloatImg *pimg, float fk, int notused);
int mirror_split(FloatImg *pimg, int kaboo); int mirror_split(FloatImg *pimg, int kaboo);
int upside_down(FloatImg *pimg); int upside_down(FloatImg *pimg);