Browse Source

fimg_contour_2x2 is working !!!

master
tth 2 years ago
parent
commit
6a33b1d318
  1. 7
      floatimg.h
  2. 5
      funcs/Makefile
  3. 70
      funcs/contour2x2.c
  4. 44
      funcs/t.c
  5. 9
      funcs/vroum.sh

7
floatimg.h

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* ugly code from tTh
*/
#define FIMG_VERSION 108
#define FIMG_VERSION 109
/*
* in memory descriptor
@ -59,7 +59,7 @@ int fimg_type_is_valid(int type); @@ -59,7 +59,7 @@ int fimg_type_is_valid(int type);
int fimg_print_version(int k);
void fimg_print_sizeof(void);
void fimg_print_sizeof(void);
void fimg_printhead(FloatImg *h);
int fimg_describe(FloatImg *head, char *txt);
char *fimg_str_type(int type);
@ -97,6 +97,9 @@ int fimg_killborders(FloatImg *img); @@ -97,6 +97,9 @@ int fimg_killborders(FloatImg *img);
int fimg_lissage_2x2(FloatImg *img);
int fimg_filter_3x3(FloatImg *s, FloatImg *d, FimgFilter3x3 *filtr);
int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int notused);
/* 'sfx0' module */
int fimg_killcolors_a(FloatImg *fimg, float fval);
int fimg_killcolors_b(FloatImg *fimg, float fval);

5
funcs/Makefile

@ -5,7 +5,7 @@ DEPS = ../floatimg.h Makefile @@ -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
hsv.o classif.o contour2x2.o
#---------------------------------------------------------------
@ -55,6 +55,9 @@ equalize.o: equalize.c $(DEPS) @@ -55,6 +55,9 @@ equalize.o: equalize.c $(DEPS)
sfx0.o: sfx0.c $(DEPS)
gcc $(COPT) -c $<
contour2x2.o: contour2x2.c $(DEPS)
gcc $(COPT) -c $<
rampes.o: rampes.c $(DEPS)
gcc $(COPT) -c $<

70
funcs/contour2x2.c

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
/*
* classif.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* --------------------------------------------------------------------- */
/* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */
int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int notused)
{
float avg[4];
int foo, x, y, q;
int tbl[] =
{
0, 1, 1, 1,
1, 1, 0, 1,
1, 0, 1, 1,
1, 1, 1, 0
};
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused);
#endif
foo = fimg_meanvalues(psrc, avg);
if (verbosity) {
fprintf(stderr, "mean values : %f %f %f\n", avg[0], avg[1], avg[2]);
}
#define RP(ix, iy) ( psrc->R[((iy)*psrc->width)+(ix)] < avg[0] )
#define GP(ix, iy) ( psrc->G[((iy)*psrc->width)+(ix)] < avg[1] )
#define BP(ix, iy) ( psrc->B[((iy)*psrc->width)+(ix)] < avg[2] )
for (y=0; y<psrc->height-1; y++) {
for (x=0; x<psrc->width-1; x++) {
q = ( ( RP(x, y) << 3 ) |
( RP(x+1, y) << 2 ) |
( RP(x, y+1) << 1 ) |
( RP(x+1, y+1) ) );
pdst->R[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ;
q = ( ( GP(x, y) << 3 ) |
( GP(x+1, y) << 2 ) |
( GP(x, y+1) << 1 ) |
( GP(x+1, y+1) ) );
pdst->G[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ;
q = ( ( BP(x, y) << 3 ) |
( BP(x+1, y) << 2 ) |
( BP(x, y+1) << 1 ) |
( BP(x+1, y+1) ) );
pdst->B[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ;
}
}
return 0;
}
/* --------------------------------------------------------------------- */

44
funcs/t.c

@ -14,6 +14,44 @@ int verbosity; @@ -14,6 +14,44 @@ int verbosity;
float global_fvalue;
/* --------------------------------------------------------------------- */
/*
* nouveau 5 octobre 2020 pendant sonoptic
*/
int essai_contour_2x2(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_contour_2x2(&src, &dst, 0);
if (foo) {
fprintf(stderr, "%s: err %d in contour_2x2\n", __func__, foo);
return foo;
}
foo = fimg_save_as_pnm(&dst, "out.pnm", 0);
if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo;
}
return 0;
}
/* --------------------------------------------------------------------- */
/*
* nouveau 5 octobre 2020 pendant sonoptic
@ -473,7 +511,7 @@ return 0; @@ -473,7 +511,7 @@ return 0;
}
/* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv,Classif };
Histo, Hsv, Classif, Ctr2x2 };
typedef struct {
char *name;
int Cmd;
@ -491,6 +529,7 @@ Command commands[] = { @@ -491,6 +529,7 @@ Command commands[] = {
{ "histo", Histo },
{ "hsv", Hsv },
{ "classif", Classif },
{ "ctr2x2", Ctr2x2 },
{ NULL, 0 }
} ;
@ -592,6 +631,9 @@ switch(opt) { @@ -592,6 +631,9 @@ switch(opt) {
case Classif:
foo = essai_classif(filename);
break;
case Ctr2x2:
foo = essai_contour_2x2(filename);
break;
default:
fprintf(stderr, "%s : bad command\n", command);
exit(1);

9
funcs/vroum.sh

@ -2,8 +2,9 @@ @@ -2,8 +2,9 @@
src=foo.fimg
maxi=111
grabopt=" s 640x480 -vv -p 0 -n 400 -c none "
maxi=179
grabopt=" s 320x240 -vv -p 0 -n 100 -c none "
for foo in $(seq 0 $maxi)
do
@ -11,7 +12,7 @@ do @@ -11,7 +12,7 @@ do
grabvidseq -$grabopt -o $src
fval=$(echo "$foo / $maxi" | bc -l)
./t -k $fval -v classif $src
./t -k $fval -v ctr2x2 $src
echo $foo $fval
@ -22,4 +23,4 @@ do @@ -22,4 +23,4 @@ do
done
convert -delay 10 v_*.pnm foo.gif
convert -delay 20 v_*.pnm foo.gif

Loading…
Cancel
Save