2020-11-10 02:07:30 +01:00
|
|
|
/*
|
|
|
|
* metriques.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2020-11-12 23:36:06 +01:00
|
|
|
#include <stdlib.h>
|
2020-11-10 03:58:18 +01:00
|
|
|
#include "../floatimg.h"
|
2020-11-12 23:36:06 +01:00
|
|
|
#include "metriques.h"
|
2020-11-10 03:58:18 +01:00
|
|
|
|
2020-11-10 02:07:30 +01:00
|
|
|
extern int verbosity;
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-12 23:36:06 +01:00
|
|
|
/*
|
|
|
|
* premier essai...
|
|
|
|
*/
|
2020-12-07 10:30:18 +01:00
|
|
|
int get_float_metric_a(FloatImg *pimg, float *where)
|
2020-11-10 02:07:30 +01:00
|
|
|
{
|
2020-11-12 23:36:06 +01:00
|
|
|
float means[4];
|
|
|
|
int foo;
|
2020-11-10 02:07:30 +01:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, pimg, where, whot);
|
|
|
|
#endif
|
|
|
|
|
2020-11-12 23:36:06 +01:00
|
|
|
foo = fimg_meanvalues(pimg, means);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "fatal error in %s\n", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
*where = means[0] + means[1] + means[2];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-12-07 22:02:08 +01:00
|
|
|
int get_float_metric_b(FloatImg *pimg, float *where)
|
|
|
|
{
|
2020-12-08 15:51:07 +01:00
|
|
|
int idx, size, nbre;
|
2020-12-07 22:02:08 +01:00
|
|
|
double adder;
|
|
|
|
|
|
|
|
adder = 0.0;
|
2020-12-08 15:51:07 +01:00
|
|
|
nbre = 0;
|
2020-12-07 22:02:08 +01:00
|
|
|
size = pimg->width * pimg->height;
|
|
|
|
for (idx=20; idx < size; idx+=42) {
|
|
|
|
adder += (double)pimg->R[idx];
|
2020-12-08 15:51:07 +01:00
|
|
|
nbre++;
|
2020-12-07 22:02:08 +01:00
|
|
|
}
|
2020-12-08 15:51:07 +01:00
|
|
|
*where = (float)(adder/(nbre+1));
|
2020-12-07 22:02:08 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int get_float_metric_from_file(char *fname, float *where, int mode)
|
2020-11-12 23:36:06 +01:00
|
|
|
{
|
|
|
|
FloatImg image;
|
|
|
|
int foo;
|
|
|
|
float fval;
|
|
|
|
|
|
|
|
foo = fimg_create_from_dump(fname, &image);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fname);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
fval = -1.0; /* sensible default value */
|
2020-12-07 22:02:08 +01:00
|
|
|
foo = get_float_metric_b(&image, &fval);
|
2020-11-12 23:36:06 +01:00
|
|
|
*where = fval;
|
|
|
|
|
|
|
|
fimg_destroy(&image);
|
|
|
|
|
|
|
|
return 0;
|
2020-11-10 02:07:30 +01:00
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|