Browse Source

added normalize function, need more tests

master
Tonton Th 3 years ago
parent
commit
cef00ac04e
  1. 5
      floatimg.h
  2. 35
      lib/fimg-math.c
  3. 36
      lib/t.c

5
floatimg.h

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 85
#define FIMG_VERSION 86
/*
* in memory descriptor
@ -51,7 +51,7 @@ typedef struct { @@ -51,7 +51,7 @@ typedef struct {
int fimg_create(FloatImg *fimg, int w, int h, int t);
int fimg_destroy(FloatImg *fimg);
int fimg_clone(FloatImg *fimg, FloatImg *newpic, int flags);
int fimg_copy_data(FloatImg *from, FloatImg *to);
int fimg_copy_data(FloatImg *from, FloatImg *to);
int fimg_print_version(int k);
void fimg_printhead(FloatImg *h);
@ -107,6 +107,7 @@ int fimg_meanvalues(FloatImg *head, float means[4]); @@ -107,6 +107,7 @@ int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_cste(FloatImg *fi, float value);
int fimg_normalize(FloatImg *fi, double maxima, int notused);
void fimg_drand48(FloatImg *fi, float kmul);
int fimg_count_negativ(FloatImg *fi);

35
lib/fimg-math.c

@ -158,14 +158,43 @@ if (fi->type != FIMG_TYPE_RGB) { @@ -158,14 +158,43 @@ if (fi->type != FIMG_TYPE_RGB) {
}
nbre = fi->width * fi->height * fi->type;
// #if DEBUG_LEVEL
fprintf(stderr, "%s, nbre is %d\n", __func__, nbre);
// #endif
#if DEBUG_LEVEL
fprintf(stderr, "%s, nbre of datum is %d\n", __func__, nbre);
#endif
for (idx=0; idx<nbre; idx++) {
fi->R[idx] *= value;
}
}
/* ---------------------------------------------------------------- */
int fimg_normalize(FloatImg *fi, double maxima, int notused)
{
double coef;
if (fi->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return -99;
}
if (fi->count < 1) {
fprintf(stderr, "%s : count %d is invalid\n", __func__, fi->count);
return -98;
}
coef = 1.0 / ((double)fi->count * (double)fi->fval);
if (verbosity) {
fprintf(stderr, "image @ %p\n", fi);
fprintf(stderr, "fval %f\n", fi->fval);
fprintf(stderr, "count %d\n", fi->count);
fprintf(stderr, "coef %f\n", coef);
}
fimg_mul_cste(fi, coef);
return 0;
}
/* ---------------------------------------------------------------- */
/* Warning: this function is _very_ slow */
void fimg_drand48(FloatImg *fi, float kmul)
{

36
lib/t.c

@ -13,6 +13,36 @@ @@ -13,6 +13,36 @@
int verbosity;
/* ---------------------------------------------------------------- */
int essai_normalize(void)
{
FloatImg A;
float val;
int foo;
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
fimg_drand48(&A, 255.0);
val = fimg_get_maxvalue(&A);
fprintf(stderr, "BEFORE max pixel %f\n", val);
A.fval = 255.0; A.count = 1;
foo = fimg_normalize(&A, 1.0, 0);
if (foo) {
fprintf(stderr, "%s err normalize A %d\n", __func__, foo);
return foo;
}
val = fimg_get_maxvalue(&A);
fprintf(stderr, "AFTER max pixel %f\n", val);
return 0;
}
/* ---------------------------------------------------------------- */
int essai_2gray(FloatImg *picz, char *outname)
@ -126,7 +156,7 @@ return -1; @@ -126,7 +156,7 @@ return -1;
#define H 240
int main(int argc, char *argv[])
{
int foo, idx, opt;
int foo, opt;
// char outname[100];
int gray = 0;
@ -140,8 +170,8 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) { @@ -140,8 +170,8 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) {
if (verbosity) fimg_print_version(0);
foo = essai_clone_et_copy(0);
fprintf(stderr, "retour essai clone_et_copy -> %d\n", foo);
foo = essai_normalize();
fprintf(stderr, "retour essai normalize -> %d\n", foo);
return 0;
}

Loading…
Cancel
Save