From b1bf9715e03ace17183ec7eca77ab90e0a813f1d Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 4 Oct 2020 13:05:28 +0200 Subject: [PATCH] added "classif" kludgy func --- doc/the_floatimg_hack.tex | 2 +- funcs/Makefile | 5 ++- funcs/classif.c | 89 +++++++++++++++++++++++++++++++++++++++ funcs/t.c | 45 +++++++++++++++++++- 4 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 funcs/classif.c diff --git a/doc/the_floatimg_hack.tex b/doc/the_floatimg_hack.tex index e338bbdf..1be7e06e 100644 --- a/doc/the_floatimg_hack.tex +++ b/doc/the_floatimg_hack.tex @@ -412,7 +412,7 @@ foo = fimg_create_from_dump("lena.fimg", &head); \end{lstlisting} Si la valeur retournée est différente de 0, c'est que quelque -chose s'est mal passé. +chose s'est probablement mal passé. Certains messages sont parfois explicites. % _________ diff --git a/funcs/Makefile b/funcs/Makefile index 147d364f..bea3a39e 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -5,7 +5,7 @@ DEPS = ../floatimg.h Makefile OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \ equalize.o fimg-fits.o saturation.o histogram.o \ - hsv.o + hsv.o classif.o #--------------------------------------------------------------- @@ -58,6 +58,9 @@ sfx0.o: sfx0.c $(DEPS) rampes.o: rampes.c $(DEPS) gcc $(COPT) -c $< +classif.o: classif.c $(DEPS) + gcc $(COPT) -c $< + hsv.o: hsv.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/classif.c b/funcs/classif.c new file mode 100644 index 00000000..09f7392f --- /dev/null +++ b/funcs/classif.c @@ -0,0 +1,89 @@ +/* + * classif.c + */ + +#include +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* --------------------------------------------------------------------- */ +/* nouveau 2 octobre 2020, juste avant sonoptic de la pluie craignos */ + +int fimg_classif_trial(FloatImg *psrc, FloatImg *pdst, int notused) +{ +float minmax[6], delta[3], baryc[3]; +float range, dist, rgb[3], dr, dg, db; +int x, y, on, off; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused); +#endif + +/* calculer les amplitudes RGB de l'image source */ +fimg_get_minmax_rgb(psrc, minmax); +delta[0] = minmax[1] - minmax[0]; +delta[1] = minmax[3] - minmax[2]; +delta[2] = minmax[5] - minmax[4]; + +/* chercher le plus petit des deltas */ +range = delta[0]; if (delta[1]height; y++) { + for (x=0; xwidth; x++) { + + fimg_get_rgb(psrc, x, y, rgb); + + /* calcul de la distance chromatique */ + dr = rgb[0] - baryc[0]; + dg = rgb[1] - baryc[1]; + db = rgb[2] - baryc[2]; + + dist = sqrtf( (dr*dr) + (dg*dg) + (db*db) ); + +#if DEBUG_LEVEL + if (x==y) fprintf(stderr, "%4d %4d %f\n", x, y, dist); +#endif + + /* action !!! */ + if (dist > range) { + rgb[0] = 0; on++; + } + else { + rgb[1] = 0; off++; + } + + fimg_put_rgb(pdst, x, y, rgb); + + /* MUST BE MORE CREATIVE HERE !!! */ + } + } + +fprintf(stderr, "on %d off %d\n", on, off); + +return 0; +} + +/* --------------------------------------------------------------------- */ + + diff --git a/funcs/t.c b/funcs/t.c index c8afb2b8..94d46f64 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -14,6 +14,44 @@ int verbosity; float global_fvalue; +/* --------------------------------------------------------------------- */ + +int fimg_classif_trial(FloatImg *src, FloatImg*dst, int notused); + +int essai_classif(char *infile) +{ +FloatImg src, dst; +int foo; + +if (NULL != infile) { + fprintf(stderr, "%s: loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &src); + if (foo) { + fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +fimg_clone(&src, &dst, 1); + +foo = fimg_classif_trial(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s: err %d in classif_trial\n", __func__, foo); + return foo; + } + +foo = fimg_save_as_pnm(&dst, "out.pnm", 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +return foo; +} /* --------------------------------------------------------------------- */ /* nouveau 19 aout 2020, le matin avant la canicule */ @@ -31,7 +69,6 @@ if (foo) { return foo; } - return -7; } /* --------------------------------------------------------------------- */ @@ -434,7 +471,7 @@ return 0; } /* --------------------------------------------------------------------- */ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, - Histo, Hsv }; + Histo, Hsv,Classif }; typedef struct { char *name; int Cmd; @@ -451,6 +488,7 @@ Command commands[] = { { "wtiff", Wtiff }, { "histo", Histo }, { "hsv", Hsv }, + { "classif", Classif }, { NULL, 0 } } ; @@ -547,6 +585,9 @@ switch(opt) { case Hsv: foo = fimg_essai_hsv(filename); break; + case Classif: + foo = essai_classif(filename); + break; default: fprintf(stderr, "%s : bad command\n", command); exit(1);