thermocolor, first try

This commit is contained in:
tTh 2024-03-20 18:44:06 +01:00
parent c598c4a2c0
commit 83e577b89a
5 changed files with 107 additions and 2 deletions

View File

@ -9,7 +9,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 rectangle.o \ fimg-libpnm.o rampes.o rectangle.o \
sfx0.o sfx1.o sfx2.o sfx3.o sfx4.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 \ geometry.o rotate.o fimg-openexr.o \
equalize.o fimg-fits.o saturation.o histogram.o \ equalize.o fimg-fits.o saturation.o histogram.o \
fimg-dicom.o \ fimg-dicom.o \
@ -144,6 +144,8 @@ exporter.o: exporter.c $(DEPS)
falsecolors.o: falsecolors.c $(DEPS) falsecolors.o: falsecolors.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<
thermocolor.o: thermocolor.c $(DEPS)
gcc $(COPT) -c $<
hsv.o: hsv.c $(DEPS) hsv.o: hsv.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

View File

@ -26,7 +26,7 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Geometrie, FileType, Mirror, KillRGB, Geometrie, FileType, Mirror, KillRGB,
Pixelize,SplitLevel, DecompRgbz, DecompRgbg, Pixelize,SplitLevel, DecompRgbz, DecompRgbg,
Rectangle, Dicom, Fakolor0, Fakolor3, Rectangle, Dicom, Fakolor0, Fakolor3,
Fmorpho0, Fluffy }; Fmorpho0, Fluffy, ThermoCol };
typedef struct { typedef struct {
char *name; char *name;
int Cmd; int Cmd;
@ -65,6 +65,7 @@ Command commands[] = {
{ "fakolor3", Fakolor3 }, { "fakolor3", Fakolor3 },
{ "fmorpho0", Fmorpho0 }, { "fmorpho0", Fmorpho0 },
{ "fluffy", Fluffy }, { "fluffy", Fluffy },
{ "thermocol", ThermoCol },
{ NULL, 0 } { NULL, 0 }
} ; } ;
@ -266,6 +267,11 @@ switch(opt) {
case Fluffy: case Fluffy:
foo = essai_rndfluffy(filename, outfile, 0); foo = essai_rndfluffy(filename, outfile, 0);
break; break;
case ThermoCol:
foo = essai_thermocol(filename, outfile);
fprintf(stderr, "retour thermocolor = %d\n", foo);
break;
default: default:
fprintf(stderr, "'%s' is a bad command\n", command); fprintf(stderr, "'%s' is a bad command\n", command);
exit(1); exit(1);

View File

@ -1173,3 +1173,37 @@ fimg_destroy(&dst);
return 0; 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;
}
/* --------------------------------------------------------------------- */

View File

@ -30,6 +30,7 @@ int essai_detect_type(void);
int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */
int essai_histogramme(char *fname, int k); int essai_histogramme(char *fname, int k);
int essai_0_fausses_couleurs(char *dstfile, int type); 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); int essai_lecture_png(char *fname, char *outfile, int notused);

62
funcs/thermocolor.c Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#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; idx<surface; idx++) {
gray = src->R[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; idx<surface; idx++) {
gray = src->R[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;
}
/* --------------------------------------------------------------------- */