new func: the max of max

This commit is contained in:
tTh 2023-10-07 19:19:49 +02:00
parent cfe9f8cdae
commit 2699476135
3 changed files with 71 additions and 8 deletions

View File

@ -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);

View File

@ -116,7 +116,37 @@ for (idx=0; idx<surface; idx++) {
else if (fval > 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; idx<surface; idx++) {
fval = img->R[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])

View File

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#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<argc; idx++) {
#if DEBUG_LEVEL
fprintf(stderr, "%5d %s\n", idx, argv[idx]);
fprintf(stderr, "---------------- %s\n", argv[idx]);
fflush(stderr);
#endif
foo = testfile(argv[idx]);
if (foo) {
@ -93,8 +100,15 @@ for (idx=optind; idx<argc; idx++) {
exit(1);
}
/*
* load the picture, create a clone of the first
*/
if ( ! src_loaded ) {
foo = fimg_create_from_dump(argv[idx], &accu);
if (foo) {
fprintf(stderr, "create from dump -> %d\n", foo);
exit(1);
}
fimg_clone(&accu, &temp, 0);
src_loaded = 1;
}
@ -104,8 +118,20 @@ for (idx=optind; idx<argc; idx++) {
fprintf(stderr, "load from dump -> %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;
}
/* --------------------------------------------------------------------- */