From 26994761356ba179927f1b9e8be3496f248012fc Mon Sep 17 00:00:00 2001 From: tTh Date: Sat, 7 Oct 2023 19:19:49 +0200 Subject: [PATCH] new func: the max of max --- floatimg.h | 4 +++- lib/fimg-math.c | 32 +++++++++++++++++++++++++++++++- tools/cumulfimgs.c | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/floatimg.h b/floatimg.h index 1b95c471..f713bf30 100644 --- a/floatimg.h +++ b/floatimg.h @@ -20,7 +20,7 @@ * https://git.tetalab.org/tTh/FloatImg */ -#define FIMG_VERSION (226) +#define FIMG_VERSION (227) #define RELEASE_NAME ("noname") #define PATCH_LEVEL ("aaaa") @@ -308,6 +308,8 @@ void fimg_drand48(FloatImg *fi, float kmul); long fimg_count_negativ(FloatImg *fi); long fimg_clamp_negativ(FloatImg *fi); +int fimg_max_of_max(FloatImg *img, float maxes[3]); + /* various funcs modules */ int fimg_load_from_png(char *filename, FloatImg *fimg); int fimg_create_from_png(char *filename, FloatImg *fimg); diff --git a/lib/fimg-math.c b/lib/fimg-math.c index 50ecc0c4..de6799df 100644 --- a/lib/fimg-math.c +++ b/lib/fimg-math.c @@ -116,7 +116,37 @@ for (idx=0; idx mmvals[5]) mmvals[5] = fval; } -return -0; +return 0; +} +/* ---------------------------------------------------------------- */ +/* new: Fri Oct 6 19:51:28 UTC 2023 + * + * can compute the maxima of a lot of pictures... + */ + +fimg_max_of_max(FloatImg *img, float maxes[3]) +{ +float localmax[3]; +int idx, surface; +float fval; + +localmax[0] = localmax[1] = localmax[2] = -1e9; + +surface = img->width * img->height; +for (idx=0; idxR[idx]; + if (fval > localmax[0]) localmax[0] = fval; + fval = img->G[idx]; + if (fval > localmax[1]) localmax[1] = fval; + fval = img->B[idx]; + if (fval > localmax[2]) localmax[2] = fval; + } + +if (localmax[0] > maxes[0]) maxes[0] = localmax[0]; +if (localmax[1] > maxes[1]) maxes[1] = localmax[1]; +if (localmax[2] > maxes[2]) maxes[2] = localmax[2]; + +return 0; } /* ---------------------------------------------------------------- */ int fimg_meanvalues(FloatImg *head, float means[4]) diff --git a/tools/cumulfimgs.c b/tools/cumulfimgs.c index 29c75205..b39d503d 100644 --- a/tools/cumulfimgs.c +++ b/tools/cumulfimgs.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "../floatimg.h" @@ -41,11 +42,12 @@ puts(""); puts("$ cumulfimgs a.fimg b.fimg c-fimg ..."); puts("cumulator options :"); puts("\t-g\tconvert to gray level"); +puts("\t-m\tcompute the max of the maxes"); puts("\t-o\tname of output file"); puts("\t-s\trescale end image"); puts("\t-v\tincrease verbosity"); puts(""); -if (verbosity) { puts("Xperiment"); fimg_print_version(v); } +fimg_print_version(v); exit(0); } /* --------------------------------------------------------------------- */ @@ -59,17 +61,19 @@ int to_gray = 0; int experiment = 0; int rescale = 0; int src_loaded = 0; +int minmax = 0; char *output_file = "out.fimg"; FloatImg accu, temp; -float vals[6]; +float vals[3]; g_width = g_height = 0; -while ((opt = getopt(argc, argv, "gho:svx")) != -1) { +while ((opt = getopt(argc, argv, "ghmo:svx")) != -1) { switch(opt) { case 'g': to_gray = 1; break; case 'h': help(1); break; + case 'm': minmax++; break; case 'o': output_file = optarg; break; case 's': rescale = 1; break; case 'v': verbosity++; break; @@ -83,9 +87,12 @@ if (verbosity) fprintf(stderr, "------ cumulfimgs ------\n"); fprintf(stderr, "argc = %d, optind = %d\n", argc, optind); #endif +memset(vals, 0, 3*sizeof(float)); + for (idx=optind; idx %d\n", foo); + exit(1); + } fimg_clone(&accu, &temp, 0); src_loaded = 1; } @@ -104,8 +118,20 @@ for (idx=optind; idx %d\n", foo); exit(1); } - fimg_add_2(&temp, &accu); } + + if (minmax) { + /* + * print the maximum values and compute the + * maximum of all the maximums + */ + foo = fimg_max_of_max(&temp, vals); + // fprintf(stderr, "%5d max of max %9.3f %9.3f %9.3f\n", + // idx, vals[0], vals[1], vals[2]); + } + + fimg_add_2(&temp, &accu); + compte++; } @@ -120,6 +146,9 @@ if (experiment) { } /* XXX */ +fprintf(stderr, "max of max %9.3f %9.3f %9.3f\n", + vals[0], vals[1], vals[2]); + if (to_gray) { foo = fimg_desaturate(&accu, &accu, 0); @@ -156,6 +185,8 @@ if (verbosity) { vals[4], vals[5], vals[5]-vals[4]); } +fimg_destroy(&accu); fimg_destroy(&temp); + return 0; } /* --------------------------------------------------------------------- */