From 2ee1645a4a0715bc4d4f4f4e42162f71d9b78cb5 Mon Sep 17 00:00:00 2001 From: tth Date: Tue, 12 Nov 2019 00:20:28 +0100 Subject: [PATCH] trying some contrast funcs... --- lib/Makefile | 5 +++- lib/contrast.c | 64 ++++++++++++++++++++++++++++++++++++++++++ lib/t.c | 76 +++++++++++++++++++------------------------------- 3 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 lib/contrast.c diff --git a/lib/Makefile b/lib/Makefile index 4980a4cd..ea2e3d43 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,7 +5,7 @@ COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \ fimg-timers.o operators.o fimg-2gray.o \ - interpolate.o fimg-compare.o + interpolate.o fimg-compare.o contrast.o DEPS = Makefile ../floatimg.h @@ -34,6 +34,9 @@ fimg-2gray.o: fimg-2gray.c $(DEPS) operators.o: operators.c $(DEPS) gcc $(COPT) -c $< +contrast.o: contrast.c $(DEPS) + gcc $(COPT) -c $< + interpolate.o: interpolate.c $(DEPS) gcc $(COPT) -c $< diff --git a/lib/contrast.c b/lib/contrast.c new file mode 100644 index 00000000..09dff298 --- /dev/null +++ b/lib/contrast.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* ---------------------------------------------------------------- */ +int fimg_square_root(FloatImg *s, FloatImg *d, double maxval) +{ +int nbre, idx; +double dval; + +if (s->type != FIMG_TYPE_RGB) { + fprintf(stderr, "%s : type %d invalide\n", + __func__, s->type); + return -4; + } + +if (NULL==d) { + d = s; + } + + +nbre = s->width * s->height * 3; + +for (idx=0; idxR[idx] / maxval; + d->R[idx] = maxval * sqrt(dval); + } + +return -1; +} +/* ---------------------------------------------------------------- */ +int fimg_power_2(FloatImg *s, FloatImg *d, double maxval) +{ +int nbre, idx; +double dval; + +if (s->type != FIMG_TYPE_RGB) { + fprintf(stderr, "%s : type %d invalide\n", + __func__, s->type); + return -4; + } + +if (NULL==d) { + d = s; + } + + +nbre = s->width * s->height * 3; + +for (idx=0; idxR[idx] / maxval; + d->R[idx] = maxval * dval * dval; + } + +return -1; +} + +/* ---------------------------------------------------------------- */ diff --git a/lib/t.c b/lib/t.c index f2a0eb29..6534d76f 100644 --- a/lib/t.c +++ b/lib/t.c @@ -67,71 +67,53 @@ fimg_destroy(&gray); return 0; } /* ---------------------------------------------------------------- */ -/**** -foo = fimg_create(&dessin, W, H, 3); -petit_dessin(&dessin); -foo = fimg_create(&noise, W, H, 3); -fimg_drand48(&noise, 0.1); -****/ + +int fimg_square_root(FloatImg *s, FloatImg *d, double maxval); +int fimg_power_2(FloatImg *s, FloatImg *d, double maxval); + +int essai_contraste(char *fname) +{ +int foo; +FloatImg dessin; +double maxi; + +foo = fimg_create_from_dump(fname, &dessin); + +maxi = (double)fimg_get_maxvalue(&dessin); +fprintf(stderr, "avant valeur maxi = %f\n", maxi); + +fimg_power_2(&dessin, NULL, maxi); + +maxi = (double)fimg_get_maxvalue(&dessin); +fprintf(stderr, "apres valeur maxi = %f\n", maxi); + +fimg_dump_to_file(&dessin, "dst.fimg", 0); + +fimg_destroy(&dessin); + +return -1; +} /* ---------------------------------------------------------------- */ #define W 320 #define H 240 int main(int argc, char *argv[]) { int foo, idx, opt; -float coef; -FloatImg dessin, noise, result; -char outname[100]; +// char outname[100]; int gray = 0; -int nb_img = 42; while ((opt = getopt(argc, argv, "gn:v")) != -1) { switch(opt) { case 'g': gray++; break; - case 'n': nb_img=atoi(optarg); break; + case 'n': foo=atoi(optarg); break; case 'v': verbosity++; break; } } if (verbosity) fimg_print_version(0); +foo = essai_contraste("src.fimg"); -foo = fimg_create_from_png("/home/tth/TMP/floatimg/s1.png", &dessin); -if (foo) { - fprintf(stderr, "s1 load err %d\n", foo); - exit(1); - } -if (verbosity) fimg_describe(&dessin, "s1 dessin"); -if (gray) fimg_to_gray(&dessin); - -foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &noise); -if (foo) { - fprintf(stderr, "s2 load err %d\n", foo); - exit(1); - } -if (verbosity) fimg_describe(&noise, "s2 noise"); -fimg_mul_cste(&noise, 0.50); -if (gray) fimg_to_gray(&noise); - -foo = fimg_create(&result, W, H, 3); -if (verbosity) fimg_describe(&result, "d result"); - -fprintf(stderr, "running for %d picz\n", nb_img); - -for (idx=0; idx