From 12197cc1716279437554401b63eb5d0c9eaadac4 Mon Sep 17 00:00:00 2001 From: tth Date: Thu, 14 Nov 2019 14:23:12 +0100 Subject: [PATCH] adding the COS01 contrast method --- floatimg.h | 1 + lib/Makefile | 2 +- lib/contrast.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- lib/runme.sh | 13 ++++++++++--- lib/t.c | 13 ++++++++----- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/floatimg.h b/floatimg.h index 9a50ebc7..126172f3 100644 --- a/floatimg.h +++ b/floatimg.h @@ -73,6 +73,7 @@ double fimg_timer_get(int whot); /* --> lib/contrast.c */ int fimg_square_root(FloatImg *s, FloatImg *d, double maxval); int fimg_power_2(FloatImg *s, FloatImg *d, double maxval); +int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval); int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k); diff --git a/lib/Makefile b/lib/Makefile index ac584143..ea2e3d43 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,7 +2,7 @@ # building the base library # -COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=1 +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 contrast.o diff --git a/lib/contrast.c b/lib/contrast.c index 09dff298..377ae575 100644 --- a/lib/contrast.c +++ b/lib/contrast.c @@ -41,7 +41,7 @@ int nbre, idx; double dval; if (s->type != FIMG_TYPE_RGB) { - fprintf(stderr, "%s : type %d invalide\n", + fprintf(stderr, "%s : src type %d invalide\n", __func__, s->type); return -4; } @@ -49,6 +49,13 @@ if (s->type != FIMG_TYPE_RGB) { if (NULL==d) { d = s; } +else { + if (d->type != FIMG_TYPE_RGB) { + fprintf(stderr, "%s : dst type %d invalide\n", + __func__, s->type); + return -4; + } + } nbre = s->width * s->height * 3; @@ -58,7 +65,42 @@ for (idx=0; idxR[idx] = maxval * dval * dval; } -return -1; +return 0; } /* ---------------------------------------------------------------- */ +/* + #macro Cos_01( X ) + (0.5-0.5*cos( 3.141592654 * X)) + #end + + */ +int fimg_cos_01(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 * (0.5 - 0.5 * cos(3.141592654*dval)); + } + +return 0; +} +/* ---------------------------------------------------------------- */ + +/* ---------------------------------------------------------------- */ + diff --git a/lib/runme.sh b/lib/runme.sh index 89144e76..f0bb3d99 100755 --- a/lib/runme.sh +++ b/lib/runme.sh @@ -1,11 +1,16 @@ #!/bin/bash + +grabvidseq -s 960x720 -n 60 -p 0.5 -vv -o original.fimg + make t && ./t -for picz in src power2 squareroot +for picz in original power2 squareroot cos_01 do - ../tools/fimgstats -v ${picz}.fimg + echo _______________ ${picz} + + # ../tools/fimgstats -v ${picz}.fimg ../tools/fimg2pnm -v ${picz}.fimg ${picz}.pnm convert -pointsize 36 \ @@ -13,7 +18,9 @@ do -fill black -annotate +12+30 "${picz}" \ ${picz}.pnm ${picz}.png + rm ${picz}.pnm + done -convert -delay 50 *.png foo.gif +convert -delay 150 *.png foo.gif diff --git a/lib/t.c b/lib/t.c index 35585942..d5af6355 100644 --- a/lib/t.c +++ b/lib/t.c @@ -75,23 +75,26 @@ FloatImg dessin, copy; double maxi; foo = fimg_create_from_dump(fname, &dessin); - foo = fimg_clone(&dessin, ©, 0); maxi = (double)fimg_get_maxvalue(&dessin); -fprintf(stderr, "avant power_2 valeur maxi = %f\n", maxi); +fprintf(stderr, "image source valeur maxi = %f\n", maxi); fimg_power_2(&dessin, ©, maxi); -maxi = (double)fimg_get_maxvalue(&dessin); +maxi = (double)fimg_get_maxvalue(©); fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi); fimg_dump_to_file(©, "power2.fimg", 0); fimg_square_root(&dessin, ©, maxi); -maxi = (double)fimg_get_maxvalue(&dessin); +maxi = (double)fimg_get_maxvalue(©); fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi); fimg_dump_to_file(©, "squareroot.fimg", 0); +fimg_cos_01(&dessin, ©, maxi); +maxi = (double)fimg_get_maxvalue(©); +fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi); +fimg_dump_to_file(©, "cos_01.fimg", 0); fimg_destroy(&dessin); @@ -116,7 +119,7 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) { if (verbosity) fimg_print_version(0); -foo = essai_contraste("src.fimg"); +foo = essai_contraste("original.fimg"); fprintf(stderr, "retour essai contraste -> %d\n", foo); return 0;