adding the COS01 contrast method

This commit is contained in:
Tonton Th 2019-11-14 14:23:12 +01:00
parent e81055756e
commit 12197cc171
5 changed files with 64 additions and 11 deletions

View File

@ -73,6 +73,7 @@ double fimg_timer_get(int whot);
/* --> lib/contrast.c */ /* --> lib/contrast.c */
int fimg_square_root(FloatImg *s, FloatImg *d, double maxval); int fimg_square_root(FloatImg *s, FloatImg *d, double maxval);
int fimg_power_2(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); int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k);

View File

@ -2,7 +2,7 @@
# building the base library # 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 \ OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
fimg-timers.o operators.o fimg-2gray.o \ fimg-timers.o operators.o fimg-2gray.o \
interpolate.o fimg-compare.o contrast.o interpolate.o fimg-compare.o contrast.o

View File

@ -41,7 +41,7 @@ int nbre, idx;
double dval; double dval;
if (s->type != FIMG_TYPE_RGB) { if (s->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n", fprintf(stderr, "%s : src type %d invalide\n",
__func__, s->type); __func__, s->type);
return -4; return -4;
} }
@ -49,6 +49,13 @@ if (s->type != FIMG_TYPE_RGB) {
if (NULL==d) { if (NULL==d) {
d = s; 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; nbre = s->width * s->height * 3;
@ -58,7 +65,42 @@ for (idx=0; idx<nbre; idx++) {
d->R[idx] = maxval * dval * dval; 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;
}
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */

View File

@ -1,11 +1,16 @@
#!/bin/bash #!/bin/bash
grabvidseq -s 960x720 -n 60 -p 0.5 -vv -o original.fimg
make t && ./t make t && ./t
for picz in src power2 squareroot for picz in original power2 squareroot cos_01
do do
../tools/fimgstats -v ${picz}.fimg echo _______________ ${picz}
# ../tools/fimgstats -v ${picz}.fimg
../tools/fimg2pnm -v ${picz}.fimg ${picz}.pnm ../tools/fimg2pnm -v ${picz}.fimg ${picz}.pnm
convert -pointsize 36 \ convert -pointsize 36 \
@ -13,7 +18,9 @@ do
-fill black -annotate +12+30 "${picz}" \ -fill black -annotate +12+30 "${picz}" \
${picz}.pnm ${picz}.png ${picz}.pnm ${picz}.png
rm ${picz}.pnm
done done
convert -delay 50 *.png foo.gif convert -delay 150 *.png foo.gif

13
lib/t.c
View File

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