two new operators (mini & maxi)

This commit is contained in:
tth 2019-11-20 11:12:16 +01:00
parent ca4bfcff05
commit b62b5a4805
6 changed files with 83 additions and 10 deletions

View File

@ -10,4 +10,10 @@
[794365.892937] usb 4-5: SerialNumber: 00000 [794365.892937] usb 4-5: SerialNumber: 00000
Comment imprimer ce code trop gruik ?
enscript -o - -Ec -f Courier9 -F Times-Roman14 --word-wrap \
-i 6 --swap-even-page-margins v4l2_pr_structs.c |
ps2pdf - /media/tth/BLIRBOU/v4l2_pr_structs.pdf

View File

@ -388,7 +388,9 @@ le calcul de la variance\index{variance}.
\subsection{fimgops}\index{fimgops}\label{fimgops} \subsection{fimgops}\index{fimgops}\label{fimgops}
Operations diverses sur ou entre des images. Operations diverses entre deeux images, qui doivent être
de la même taille, et du même type \textsl{pour le moment,
uniquement RGB}.
\begin{verbatim} \begin{verbatim}
usage: usage:
@ -398,14 +400,16 @@ operators:
sub 2 sub 2
mix 3 mix 3
mul 4 mul 4
mini 5
maxi 6
options: options:
-g convert output to gray -g convert output to gray
-k N.N set float value -k N.N set float value
-v increase verbosity -v increase verbosity
\end{verbatim} \end{verbatim}
Pour des operateurs paramétrable (comme \texttt{mix}), le paramêtre flottant doit Pour des operateurs paramétrable (comme \texttt{mix}), le paramêtre
être fourni en utilisant l'option \texttt{-k}. flottant doit être fourni en utilisant l'option \texttt{-k}.
La véracité mathématique n'est pas garantie. La véracité mathématique n'est pas garantie.
\subsection{fimg2png, fimg2pnm, fimg2tiff} \subsection{fimg2png, fimg2pnm, fimg2tiff}

View File

@ -2,7 +2,7 @@
* floatimg.h * floatimg.h
*/ */
#define FIMG_VERSION 76 #define FIMG_VERSION 77
/* /*
* in memory descriptor * in memory descriptor
@ -68,6 +68,8 @@ int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef);
int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d);
/* PNM files module */ /* PNM files module */
int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); int fimg_save_as_pnm(FloatImg *head, char *fname, int flags);

View File

@ -66,7 +66,6 @@ for (idx=0; idx<nbiter; idx++) {
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
/* /*
* A * B -> D * A * B -> D
*/ */
@ -94,3 +93,53 @@ for (idx=0; idx<nbiter; idx++) {
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d)
{
int idx, nbiter;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
#endif
if (3 != a->type || 3 != b->type || 3 != d->type) {
fprintf(stderr, "%s : got a bad type fimg\n", __func__);
return -8;
}
nbiter = a->width * a->height * 3;
for (idx=0; idx<nbiter; idx++) {
if (a->R[idx] > b->R[idx])
d->R[idx] = a->R[idx];
else
d->R[idx] = b->R[idx];
}
return 0;
}
/* ---------------------------------------------------------------- */
int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d)
{
int idx, nbiter;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
#endif
if (3 != a->type || 3 != b->type || 3 != d->type) {
fprintf(stderr, "%s : got a bad type fimg\n", __func__);
return -8;
}
nbiter = a->width * a->height * 3;
for (idx=0; idx<nbiter; idx++) {
if (a->R[idx] < b->R[idx])
d->R[idx] = a->R[idx];
else
d->R[idx] = b->R[idx];
}
return 0;
}
/* ---------------------------------------------------------------- */

View File

@ -1,13 +1,17 @@
#!/bin/bash #!/bin/bash
../v4l2/grabvidseq -s 960x720 -n 10000 -p 0.193 \ ../v4l2/grabvidseq -s 960x720 -n 100 -p 0.193 \
-vv -g -c none \ -vv -c none \
-o original.fimg -o original.fimg
make t && ./t make t && ./t
for picz in original power2 squareroot cos_01 ../tools/fimgops original.fimg cos_01.fimg mini minimum.fimg
../tools/fimgops original.fimg cos_01.fimg maxi maximum.fimg
for picz in original power2 squareroot cos_01 minimum maximum
do do
echo _______________________ ${picz} echo _______________________ ${picz}

View File

@ -16,6 +16,8 @@ float global_fvalue;
#define OP_SUB 2 #define OP_SUB 2
#define OP_MIX 3 #define OP_MIX 3
#define OP_MUL 4 #define OP_MUL 4
#define OP_MINI 5
#define OP_MAXI 6
typedef struct { typedef struct {
int code; int code;
char *op; char *op;
@ -26,6 +28,8 @@ Opcode opcodes[] = {
{ OP_SUB, "sub" }, { OP_SUB, "sub" },
{ OP_MIX, "mix" }, { OP_MIX, "mix" },
{ OP_MUL, "mul" }, { OP_MUL, "mul" },
{ OP_MINI, "mini" },
{ OP_MAXI, "maxi" },
{ 0, NULL } { 0, NULL }
}; };
static void pr_opcodes(void) static void pr_opcodes(void)
@ -57,11 +61,11 @@ static void help(int lj)
{ {
puts("usage:\n\tfimgops [options] A.fimg B.fimg operator D.fimg"); puts("usage:\n\tfimgops [options] A.fimg B.fimg operator D.fimg");
pr_opcodes();
puts("options:"); puts("options:");
puts("\t-g convert output to gray"); puts("\t-g convert output to gray");
puts("\t-k N.N set float value"); puts("\t-k N.N set float value");
puts("\t-v increase verbosity"); puts("\t-v increase verbosity");
pr_opcodes();
if (verbosity) fimg_print_version(1); if (verbosity) fimg_print_version(1);
exit(0); exit(0);
} }
@ -83,6 +87,10 @@ switch (action) {
break; break;
case OP_MUL: case OP_MUL:
foo = fimg_add(A, B, D); break; foo = fimg_add(A, B, D); break;
case OP_MINI:
foo = fimg_maximum(A, B, D); break;
case OP_MAXI:
foo = fimg_minimum(A, B, D); break;
default: default:
foo = -99; break; foo = -99; break;
@ -125,7 +133,7 @@ if (action < 0) {
} }
/* /*
* load the two source files, and check comatibility * load the two source files, and check compatibility
*/ */
if ((foo=fimg_create_from_dump(argv[optind], &srcA))) { if ((foo=fimg_create_from_dump(argv[optind], &srcA))) {
fprintf(stderr, "read error on '%s' is %d\n", argv[optind], foo); fprintf(stderr, "read error on '%s' is %d\n", argv[optind], foo);