Browse Source

fix a critical precision issue

master
tth 3 years ago
parent
commit
252d5c62e0
  1. 13
      lib/fimg-math.c

13
lib/fimg-math.c

@ -47,21 +47,24 @@ return maxval; @@ -47,21 +47,24 @@ return maxval;
int fimg_meanvalues(FloatImg *head, float means[4])
{
int idx, surface;
double accus[4];
surface = head->width * head->height;
if (surface < 1) return -1;
memset(means, 0, 4*sizeof(float));
memset(accus, 0, 4*sizeof(double));
for (idx=0; idx<surface; idx++) {
means[0] += head->R[idx];
accus[0] += head->R[idx];
if (head->type > 2) {
means[1] += head->G[idx];
means[2] += head->B[idx];
accus[1] += head->G[idx];
accus[2] += head->B[idx];
}
}
for (idx=0; idx<4; idx++) means[idx] /= (float)surface;
for (idx=0; idx<4; idx++) {
means[idx] = (float)(accus[idx]/(double)surface);
}
return 0;
}

Loading…
Cancel
Save