From 83e577b89a2f720858646cf873bc5706f1644183 Mon Sep 17 00:00:00 2001 From: tTh Date: Wed, 20 Mar 2024 18:44:06 +0100 Subject: [PATCH] thermocolor, first try --- funcs/Makefile | 4 ++- funcs/t.c | 8 +++++- funcs/tests.c | 34 +++++++++++++++++++++++++ funcs/tests.h | 1 + funcs/thermocolor.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 funcs/thermocolor.c diff --git a/funcs/Makefile b/funcs/Makefile index af5515e9..4c376d05 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -9,7 +9,7 @@ DEPS = ../floatimg.h Makefile OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ fimg-libpnm.o rampes.o rectangle.o \ sfx0.o sfx1.o sfx2.o sfx3.o sfx4.o \ - falsecolors.o fmorpho.o \ + falsecolors.o thermocolor.o fmorpho.o \ geometry.o rotate.o fimg-openexr.o \ equalize.o fimg-fits.o saturation.o histogram.o \ fimg-dicom.o \ @@ -144,6 +144,8 @@ exporter.o: exporter.c $(DEPS) falsecolors.o: falsecolors.c $(DEPS) gcc $(COPT) -c $< +thermocolor.o: thermocolor.c $(DEPS) + gcc $(COPT) -c $< hsv.o: hsv.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/t.c b/funcs/t.c index fdc38797..025f52bb 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -26,7 +26,7 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Geometrie, FileType, Mirror, KillRGB, Pixelize,SplitLevel, DecompRgbz, DecompRgbg, Rectangle, Dicom, Fakolor0, Fakolor3, - Fmorpho0, Fluffy }; + Fmorpho0, Fluffy, ThermoCol }; typedef struct { char *name; int Cmd; @@ -65,6 +65,7 @@ Command commands[] = { { "fakolor3", Fakolor3 }, { "fmorpho0", Fmorpho0 }, { "fluffy", Fluffy }, + { "thermocol", ThermoCol }, { NULL, 0 } } ; @@ -266,6 +267,11 @@ switch(opt) { case Fluffy: foo = essai_rndfluffy(filename, outfile, 0); break; + case ThermoCol: + foo = essai_thermocol(filename, outfile); + fprintf(stderr, "retour thermocolor = %d\n", foo); + break; + default: fprintf(stderr, "'%s' is a bad command\n", command); exit(1); diff --git a/funcs/tests.c b/funcs/tests.c index 4819f188..2bffb67a 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -1173,3 +1173,37 @@ fimg_destroy(&dst); return 0; } /* --------------------------------------------------------------------- */ +/* dans ma nouvelle maison du Gers, le 20 mars 2024 */ +int essai_thermocol(char *infile, char *outfile) +{ +FloatImg src, dst; +int foo; + +fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, infile, outfile); + +memset(&src, 0, sizeof(FloatImg)); +foo = fimg_create_from_dump(infile, &src); +if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + +memset(&dst, 0, sizeof(FloatImg)); +foo = fimg_clone(&src, &dst, 0); +if (foo) return -888; + +fimg_auto_thermique(&src, &dst, 0); + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result to %s\n", __func__, + foo, outfile); + return foo; + } + +fimg_destroy(&src); +fimg_destroy(&dst); + +return 793; +} +/* --------------------------------------------------------------------- */ diff --git a/funcs/tests.h b/funcs/tests.h index 0fd7c5cb..9349d895 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -30,6 +30,7 @@ int essai_detect_type(void); int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ int essai_histogramme(char *fname, int k); int essai_0_fausses_couleurs(char *dstfile, int type); +int essai_thermocol(char *infile, char *outfile); int essai_lecture_png(char *fname, char *outfile, int notused); diff --git a/funcs/thermocolor.c b/funcs/thermocolor.c new file mode 100644 index 00000000..b924c454 --- /dev/null +++ b/funcs/thermocolor.c @@ -0,0 +1,62 @@ +/* + * FLOATIMG + * fabriquer une pseudo-image thermique + * + * new: Wed Mar 20 16:55:09 UTC 2024 dans ma maison du Gers + */ + +#include +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ + +int fimg_auto_thermique(FloatImg *src, FloatImg *dst, int k) +{ +// int x, y, off; +int idx, surface; + +float seuil, gray; +double graymean; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, k); +#endif + +if (0!=k) { + fprintf(stderr, "%s: k mus be 0, was %d\n", __func__, k); + } + +surface = src->width * src->height; +fprintf(stderr, "surface = %d\n", surface); + +graymean = 0.0; +for (idx=0; idxR[idx] + src->G[idx] + src->B[idx]; + graymean += (double)gray; + } +seuil = (float) (graymean / surface); +// fprintf(stderr, "graymean = %f seuil = %f\n", graymean, seuil); + +for (idx=0; idxR[idx] + src->G[idx] + src->B[idx]; + if (gray > seuil) { + dst->R[idx] = gray - seuil; + dst->B[idx] = seuil / 8.0; + } + else { + dst->G[idx] = gray; + dst->B[idx] = seuil / 8.0; + } + } + +return 0; +} + + +/* --------------------------------------------------------------------- */