added "classif" kludgy func

This commit is contained in:
tth 2020-10-04 13:05:28 +02:00
parent cf42543659
commit b1bf9715e0
4 changed files with 137 additions and 4 deletions

View File

@ -412,7 +412,7 @@ foo = fimg_create_from_dump("lena.fimg", &head);
\end{lstlisting} \end{lstlisting}
Si la valeur retournée est différente de 0, c'est que quelque 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. Certains messages sont parfois explicites.
% _________ % _________

View File

@ -5,7 +5,7 @@ DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ 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 \ fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \
equalize.o fimg-fits.o saturation.o histogram.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) rampes.o: rampes.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<
classif.o: classif.c $(DEPS)
gcc $(COPT) -c $<
hsv.o: hsv.c $(DEPS) hsv.o: hsv.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

89
funcs/classif.c Normal file
View File

@ -0,0 +1,89 @@
/*
* classif.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#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]<range) range=delta[1];
if (delta[2]<range) range=delta[2];
/* convertir le diametre en rayon (magic inside) */
range /= 2.0;
fprintf(stderr, "deltas : %f %f %f / %f\n",
delta[0], delta[1], delta[2], range);
/* calcul du "barycentre" chromatique */
baryc[0] = (minmax[1] + minmax[0]) / 2;
baryc[1] = (minmax[3] + minmax[2]) / 2;
baryc[2] = (minmax[5] + minmax[4]) / 2;
fprintf(stderr, "barycs : %f %f %f\n", baryc[0], baryc[1], baryc[2]);
on = off = 0;
for (y=0; y<psrc->height; y++) {
for (x=0; x<psrc->width; 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;
}
/* --------------------------------------------------------------------- */

View File

@ -14,6 +14,44 @@ int verbosity;
float global_fvalue; 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 */ /* nouveau 19 aout 2020, le matin avant la canicule */
@ -31,7 +69,6 @@ if (foo) {
return foo; return foo;
} }
return -7; return -7;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
@ -434,7 +471,7 @@ return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv }; Histo, Hsv,Classif };
typedef struct { typedef struct {
char *name; char *name;
int Cmd; int Cmd;
@ -451,6 +488,7 @@ Command commands[] = {
{ "wtiff", Wtiff }, { "wtiff", Wtiff },
{ "histo", Histo }, { "histo", Histo },
{ "hsv", Hsv }, { "hsv", Hsv },
{ "classif", Classif },
{ NULL, 0 } { NULL, 0 }
} ; } ;
@ -547,6 +585,9 @@ switch(opt) {
case Hsv: case Hsv:
foo = fimg_essai_hsv(filename); foo = fimg_essai_hsv(filename);
break; break;
case Classif:
foo = essai_classif(filename);
break;
default: default:
fprintf(stderr, "%s : bad command\n", command); fprintf(stderr, "%s : bad command\n", command);
exit(1); exit(1);