Browse Source

adding the COS01 contrast method

master
tth 3 years ago
parent
commit
12197cc171
  1. 1
      floatimg.h
  2. 2
      lib/Makefile
  3. 46
      lib/contrast.c
  4. 13
      lib/runme.sh
  5. 13
      lib/t.c

1
floatimg.h

@ -73,6 +73,7 @@ double fimg_timer_get(int whot); @@ -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);

2
lib/Makefile

@ -2,7 +2,7 @@ @@ -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

46
lib/contrast.c

@ -41,7 +41,7 @@ int nbre, idx; @@ -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) { @@ -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; idx<nbre; idx++) { @@ -58,7 +65,42 @@ for (idx=0; idx<nbre; idx++) {
d->R[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; idx<nbre; idx++) {
dval = s->R[idx] / maxval;
d->R[idx] = maxval * (0.5 - 0.5 * cos(3.141592654*dval));
}
return 0;
}
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */

13
lib/runme.sh

@ -1,11 +1,16 @@ @@ -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 @@ -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

13
lib/t.c

@ -75,23 +75,26 @@ FloatImg dessin, copy; @@ -75,23 +75,26 @@ FloatImg dessin, copy;
double maxi;
foo = fimg_create_from_dump(fname, &dessin);
foo = fimg_clone(&dessin, &copy, 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, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&dessin);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "power2.fimg", 0);
fimg_square_root(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&dessin);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "squareroot.fimg", 0);
fimg_cos_01(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_01.fimg", 0);
fimg_destroy(&dessin);
@ -116,7 +119,7 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) { @@ -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;

Loading…
Cancel
Save