Browse Source

counting negative values

master
tth 3 years ago
parent
commit
54269cc007
  1. 1
      floatimg.h
  2. 21
      lib/fimg-math.c
  3. 7
      tools/fimgstats.c

1
floatimg.h

@ -79,6 +79,7 @@ int fimg_to_gray(FloatImg *head); @@ -79,6 +79,7 @@ int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_cste(FloatImg *fi, float value);
void fimg_drand48(FloatImg *fi, float kmul);
int fimg_count_negativ(FloatImg *fi);
/* various funcs modules */
int fimg_load_from_png(char *filename, FloatImg *fimg);

21
lib/fimg-math.c

@ -108,6 +108,27 @@ for (idx=0; idx<nbre; idx++) { @@ -108,6 +108,27 @@ for (idx=0; idx<nbre; idx++) {
}
}
/* ---------------------------------------------------------------- */
int fimg_count_negativ(FloatImg *fi)
{
int nbre, idx;
int count;
if (fi->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return -1;
}
nbre = fi->width * fi->height * fi->type;
count = 0;
for (idx=0; idx<nbre; idx++) {
if (fi->R[idx] < 0.0) count++;
}
return count;
}
/* ---------------------------------------------------------------- */
void fimg_mul_cste(FloatImg *fi, float value)
{
int nbre, idx;

7
tools/fimgstats.c

@ -31,7 +31,12 @@ for (foo=0; foo<4; foo++) @@ -31,7 +31,12 @@ for (foo=0; foo<4; foo++)
printf(" %c %14.6f\n", "RGBA"[foo], moyennes[foo]);
fvalue = fimg_get_maxvalue(fimg);
printf("max value %f\n", fvalue);
printf("max value %f\n", fvalue);
foo = fimg_count_negativ(fimg);
if (foo) {
fprintf(stderr, "%d negative values\n", foo);
}
return 0;
}

Loading…
Cancel
Save