added normalize function, need more tests

This commit is contained in:
Tonton Th 2020-01-07 13:46:09 +01:00
parent 6d13293ef2
commit cef00ac04e
3 changed files with 68 additions and 8 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h * floatimg.h
*/ */
#define FIMG_VERSION 85 #define FIMG_VERSION 86
/* /*
* in memory descriptor * in memory descriptor
@ -51,7 +51,7 @@ typedef struct {
int fimg_create(FloatImg *fimg, int w, int h, int t); int fimg_create(FloatImg *fimg, int w, int h, int t);
int fimg_destroy(FloatImg *fimg); int fimg_destroy(FloatImg *fimg);
int fimg_clone(FloatImg *fimg, FloatImg *newpic, int flags); 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); int fimg_print_version(int k);
void fimg_printhead(FloatImg *h); void fimg_printhead(FloatImg *h);
@ -107,6 +107,7 @@ int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head); int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value); void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_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); void fimg_drand48(FloatImg *fi, float kmul);
int fimg_count_negativ(FloatImg *fi); int fimg_count_negativ(FloatImg *fi);

View File

@ -158,14 +158,43 @@ if (fi->type != FIMG_TYPE_RGB) {
} }
nbre = fi->width * fi->height * fi->type; nbre = fi->width * fi->height * fi->type;
// #if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "%s, nbre is %d\n", __func__, nbre); fprintf(stderr, "%s, nbre of datum is %d\n", __func__, nbre);
// #endif #endif
for (idx=0; idx<nbre; idx++) { for (idx=0; idx<nbre; idx++) {
fi->R[idx] *= value; 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 */ /* Warning: this function is _very_ slow */
void fimg_drand48(FloatImg *fi, float kmul) void fimg_drand48(FloatImg *fi, float kmul)
{ {

36
lib/t.c
View File

@ -13,6 +13,36 @@
int verbosity; 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) int essai_2gray(FloatImg *picz, char *outname)
@ -126,7 +156,7 @@ return -1;
#define H 240 #define H 240
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, idx, opt; int foo, opt;
// char outname[100]; // char outname[100];
int gray = 0; int gray = 0;
@ -140,8 +170,8 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) {
if (verbosity) fimg_print_version(0); if (verbosity) fimg_print_version(0);
foo = essai_clone_et_copy(0); foo = essai_normalize();
fprintf(stderr, "retour essai clone_et_copy -> %d\n", foo); fprintf(stderr, "retour essai normalize -> %d\n", foo);
return 0; return 0;
} }