Bibliothèque de traitements d'images en virgule flottante. http://la.buvette.org/photos/cumul/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

82 lines
1.7 KiB

/*
* metriques.c
*/
#include <stdio.h>
#include <stdlib.h>
#include "../floatimg.h"
#include "metriques.h"
extern int verbosity;
/* -------------------------------------------------------------- */
/*
* premier essai...
*/
int get_float_metric_a(FloatImg *pimg, float *where)
{
float means[4]; /* four values : R G B A */
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, pimg, where, whot);
#endif
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;
}
/* -------------------------------------------------------------- */
int get_float_metric_b(FloatImg *pimg, float *where)
{
int idx, size, nbre;
double adder;
adder = 0.0;
nbre = 0;
size = pimg->width * pimg->height;
for (idx=20; idx < size; idx+=42) {
adder += (double)pimg->R[idx];
nbre++;
}
*where = (float)(adder/(nbre+1));
return 0;
}
/* -------------------------------------------------------------- */
int get_float_metric_from_file(char *fname, float *where, int mode)
{
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 */
switch (mode) {
case 0: case 1:
foo = get_float_metric_a(&image, &fval);
break;
case 2:
foo = get_float_metric_b(&image, &fval);
break;
default:
fprintf(stderr, "%s: method %d invalid\n",
__func__, mode);
exit(1);
break; /* not reached */
}
*where = fval;
fimg_destroy(&image);
return 0;
}
/* -------------------------------------------------------------- */