Compare commits

..

3 Commits

Author SHA1 Message Date
tth
b1f8574f9d oups... 2020-10-09 01:28:11 +02:00
tth
18399a40d2 Sonoptic experiments day 4 2020-10-09 01:26:07 +02:00
tth
ceb806d19c added "qsortrgb" effect 2020-10-08 11:24:29 +02:00
10 changed files with 184 additions and 20 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ doc/co*.tex
funcs/t
funcs/*.o
funcs/*.png
funcs/V/*
funcs/*.gif
funcs/*.fits
funcs/*.tiff

View File

@ -127,8 +127,10 @@ int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval);
int fimg_mix_rgb_gray(FloatImg *img, float mix);
int fimg_shift_to_zero(FloatImg *s, FloatImg *d, float coefs[6]);
/* experimental ! */
/* * * * experimental ! */
int fimg_classif_trial(FloatImg *src, FloatImg*dst, float fval, int notused);
int fimg_qsort_rgb_a(FloatImg *psrc, FloatImg *pdst, int notused);
int fimg_qsort_rgb_b(FloatImg *psrc, FloatImg *pdst, int notused);
/* module funcs/geometry.c */
int fimg_equalize_compute(FloatImg *src, void *vptr, float vmax);
@ -163,7 +165,7 @@ int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_cste(FloatImg *fi, float value);
int fimg_normalize(FloatImg *fi, double maxima, int notused);
int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused);
void fimg_drand48(FloatImg *fi, float kmul);
int fimg_count_negativ(FloatImg *fi);
int fimg_clamp_negativ(FloatImg *fi);

View File

@ -5,7 +5,7 @@ DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \
equalize.o fimg-fits.o saturation.o histogram.o \
hsv.o classif.o contour2x2.o
hsv.o classif.o contour2x2.o qsortrgb.o
#---------------------------------------------------------------
@ -64,6 +64,10 @@ rampes.o: rampes.c $(DEPS)
classif.o: classif.c $(DEPS)
gcc $(COPT) -c $<
qsortrgb.o: qsortrgb.c $(DEPS)
gcc $(COPT) -c $<
hsv.o: hsv.c $(DEPS)
gcc $(COPT) -c $<

View File

@ -18,7 +18,8 @@ int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int notused)
{
float avg[4];
int foo, x, y, q;
int tbl[] =
int tbl[] = /* deep magic inside */
{
0, 1, 1, 1,
1, 1, 0, 1,

View File

@ -19,7 +19,7 @@ int foo;
float dr, dg, db;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, src);
fprintf(stderr, ">>> %s ( %p %p %f )\n", __func__, src, vptr, vmax);
#endif
memset(minmax, 0, 6*sizeof(float));
@ -34,9 +34,9 @@ dr = minmax[1] - minmax[0];
dg = minmax[3] - minmax[2];
db = minmax[5] - minmax[4];
printf("Rmin %12.4g Rmax %12.4g delta %12.4g\n", minmax[0], minmax[1], dr);
printf("Gmin %12.4g Gmax %12.4g delta %12.4g\n", minmax[2], minmax[3], dg);
printf("Bmin %12.4g Bmax %12.4g delta %12.4g\n", minmax[4], minmax[5], db);
printf("Rmin %12.4g max %12.4g delta %12.4g\n", minmax[0], minmax[1], dr);
printf("Gmin %12.4g max %12.4g delta %12.4g\n", minmax[2], minmax[3], dg);
printf("Bmin %12.4g max %12.4g delta %12.4g\n", minmax[4], minmax[5], db);
if ( (minmax[0]<0.0) || (minmax[2]<0.0) || (minmax[4]<0.0) ) {
fprintf(stderr, "%s: negative value ?\n", __func__);

104
funcs/qsortrgb.c Normal file
View File

@ -0,0 +1,104 @@
/*
* qsort_rgb.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* --------------------------------------------------------------------- */
/* nouveau 7 octobre 2020, juste avant sonoptic de la pluie craignos */
static int compare_a(const void *p1, const void *p2)
{
return ( *(float *)p1 < *(float *)p2 );
}
int fimg_qsort_rgb_a(FloatImg *psrc, FloatImg *pdst, int notused)
{
int foo, szimg;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused);
#endif
foo = fimg_copy_data(psrc, pdst);
szimg = pdst->width * pdst->height;
fprintf(stderr, "%s : %d pixels\n", __func__, szimg);
qsort(pdst->R, szimg, sizeof(float), compare_a);
qsort(pdst->G, szimg, sizeof(float), compare_a);
qsort(pdst->B, szimg, sizeof(float), compare_a);
return 0;
}
/* --------------------------------------------------------------------- */
typedef struct {
float sum;
float r, g, b;
} pix;
static compare_b(const void *p1, const void *p2)
{
pix *s1, *s2;
s1 = (pix *)p1;
s2 = (pix *)p2;
return ( s1->sum < s2->sum );
}
int fimg_qsort_rgb_b(FloatImg *psrc, FloatImg *pdst, int notused)
{
int x, y, szimg;
pix *ppix, *ptr;
float rgb[3];
// #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused);
// #endif
szimg = pdst->width * pdst->height;
fprintf(stderr, "%s : %d pixels\n", __func__, szimg);
ppix = calloc(szimg, sizeof(pix));
ptr = ppix; /* mobile pointer */
for (y=0; y<psrc->height; y++) {
for (x=0; x<psrc->width; x++) {
fimg_get_rgb(psrc, x, y, rgb);
ptr->sum = rgb[0] + rgb[1] + rgb[2];
ptr->r = rgb[0];
ptr->g = rgb[1];
ptr->b = rgb[2];
ptr++; /* next pixel */
}
}
qsort(ppix, szimg, sizeof(pix), compare_b);
ptr = ppix; /* mobile pointer */
for (y=0; y<psrc->height; y++) {
for (x=0; x<psrc->width; x++) {
rgb[0] = ptr->r;
rgb[1] = ptr->g;
rgb[2] = ptr->b;
fimg_put_rgb(pdst, x, y, rgb);
ptr++; /* next pixel */
}
}
free(ppix);
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -14,6 +14,48 @@ int verbosity;
float global_fvalue;
/* --------------------------------------------------------------------- */
/*
* nouveau 7 octobre 2020 pendant sonoptic
*/
//
int essai_qsort_rgb(char *infile)
{
FloatImg src, dst;
int foo;
if (NULL != infile) {
fprintf(stderr, "%s : loading %s\n", __func__, infile);
foo = fimg_create_from_dump(infile, &src);
if (foo) {
fprintf(stderr, "%s: error loading '%s'\n", __func__, infile);
return foo;
}
}
else {
fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__);
abort();
}
fimg_clone(&src, &dst, 1);
foo = fimg_qsort_rgb_b(&src, &dst, 0);
if (foo) {
fprintf(stderr, "%s: err %d in qsort_rgb\n", __func__, foo);
return foo;
}
foo = fimg_dump_to_file(&dst, "out.fimg", 0);
if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo;
}
return 0;
}
/* --------------------------------------------------------------------- */
/*
* nouveau 5 octobre 2020 pendant sonoptic
@ -511,7 +553,7 @@ return 0;
}
/* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv, Classif, Ctr2x2 };
Histo, Hsv, Classif, Ctr2x2, Qsortrgb };
typedef struct {
char *name;
int Cmd;
@ -530,6 +572,7 @@ Command commands[] = {
{ "hsv", Hsv },
{ "classif", Classif },
{ "ctr2x2", Ctr2x2 },
{ "qsortrgb", Qsortrgb },
{ NULL, 0 }
} ;
@ -634,6 +677,9 @@ switch(opt) {
case Ctr2x2:
foo = essai_contour_2x2(filename);
break;
case Qsortrgb:
foo = essai_qsort_rgb(filename);
break;
default:
fprintf(stderr, "%s : bad command\n", command);
exit(1);

View File

@ -1,11 +1,17 @@
#!/bin/bash
src=foo.fimg
maxi=49
grabopt=" -s 1280x720 -vv -p 0 -n 200 -c none "
src=/dev/shm/foo.fimg
out=out.fimg
maxi=99
W="640"
H="480"
grabopt=" -s 640x480 -v -p 0 -n 100 -c cos01 "
mkdir V
G=$(printf "%dx%d+0+0" $W $H)
for foo in $(seq 0 $maxi)
do
@ -14,14 +20,13 @@ do
grabvidseq -$grabopt -o $src
fval=$(echo "$foo / $maxi" | bc -l)
./t -k $fval -v ctr2x2 $src
./t -k $fval -v qsortrgb $src
echo $foo ' = ' $fval
echo $foo $fval
dst=$(printf "V/%03d.png" $foo)
nom=$(printf "V/%03d.pnm" $foo)
cp out.pnm $nom
echo $nom
montage $src $out -geometry $G $dst
done
convert -delay 20 V/*.pnm foo.gif
convert -delay 10 V/*.png foo.gif

View File

@ -246,7 +246,7 @@ for (idx=0; idx<nbre; idx++) {
}
}
/* ---------------------------------------------------------------- */
int fimg_normalize(FloatImg *fi, double maxima, int notused)
int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused)
{
double coef;

View File

@ -21,7 +21,7 @@ typedef struct {
} Fx;
enum fxid { Fx_cos01=5, Fx_cos010, Fx_pow2, Fx_sqrt, Fx_gray0, Fx_halfsz0,
Fx_rot90, Fx_cmixa, Fx_desat, Fx_ctr2x2,
Fx_rot90, Fx_cmixa, Fx_desat, Fx_ctr2x2, Fx_norm,
Fx_xper };
Fx fx_list[] = {
@ -36,6 +36,7 @@ Fx fx_list[] = {
{ "xper", Fx_xper, 0, 1 },
{ "desat", Fx_desat, 0, 1 },
{ "ctr2x2", Fx_ctr2x2, 0, 1 },
{ "norm", Fx_norm, 0, 1 },
{ NULL, 0, 0 }
};