Compare commits

...

4 Commits

Author SHA1 Message Date
tTh
86a903360c fimg_filtre_morpho_0 up and running 2022-11-01 09:35:40 +01:00
tTh
5d18cb6c3f add a drand48 row 2022-10-30 22:03:34 +01:00
tTh
0e77fdeb7a cosmetic 2022-10-30 13:11:30 +01:00
tTh
0cb40ae2a0 add a bit-bang row 2022-10-30 13:06:36 +01:00
8 changed files with 200 additions and 12 deletions

View File

@ -20,7 +20,7 @@
* https://git.tetalab.org/tTh/FloatImg * https://git.tetalab.org/tTh/FloatImg
*/ */
#define FIMG_VERSION (202) #define FIMG_VERSION (205)
#define RELEASE_NAME ("noname") #define RELEASE_NAME ("noname")
/* XXX add a test for stdint.h / uint32_t XXX */ /* XXX add a test for stdint.h / uint32_t XXX */
@ -218,6 +218,10 @@ int fimg_auto_shift_to_zero(FloatImg *s, FloatImg *d);
/* funcs/falsecolors.c */ /* funcs/falsecolors.c */
int fimg_falsecolors_0(FloatImg *src, FloatImg *dst, int k, float valf); int fimg_falsecolors_0(FloatImg *src, FloatImg *dst, int k, float valf);
/* funcs/fmorpho.c */
int fimg_filtre_morpho_0(FloatImg *sfimg, FloatImg *dfimg, int index);
/* --> funcs/plasmas.c */ /* --> funcs/plasmas.c */
int fimg_prototype_plasma(FloatImg *img, double time, int type); int fimg_prototype_plasma(FloatImg *img, double time, int type);

View File

@ -9,7 +9,7 @@ DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
fimg-libpnm.o rampes.o rectangle.o \ fimg-libpnm.o rampes.o rectangle.o \
sfx0.o sfx1.o sfx2.o sfx3.o sfx4.o \ sfx0.o sfx1.o sfx2.o sfx3.o sfx4.o \
falsecolors.o \ falsecolors.o fmorpho.o \
geometry.o rotate.o fimg-openexr.o \ geometry.o rotate.o fimg-openexr.o \
equalize.o fimg-fits.o saturation.o histogram.o \ equalize.o fimg-fits.o saturation.o histogram.o \
fimg-dicom.o \ fimg-dicom.o \
@ -60,6 +60,9 @@ incrustator.o: incrustator.c $(DEPS)
displacement.o: displacement.c $(DEPS) displacement.o: displacement.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<
fmorpho.o: fmorpho.c $(DEPS)
gcc $(COPT) -c $<
fimg-png.o: fimg-png.c $(DEPS) fimg-png.o: fimg-png.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

88
funcs/fmorpho.c Normal file
View File

@ -0,0 +1,88 @@
/*
* FLOATIMG
* --------
* F M O R P H O
*
* nouveau 30 septembre 2022 / integration 28 octobre 2022
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/time.h>
#include <floatimg.h>
/* --------------------------------------------------------------------- !*/
static struct
{
int x, y;
} deltas[] =
{ { -1, -1, },
{ 0, -1, },
{ 1, -1, },
{ -1, 0, },
{ 0, 0, },
{ 1, 0, },
{ -1, 1, },
{ 0, 1, },
{ 1, 1 }
};
typedef struct
{
int x, y; // not used
float r, g, b;
float fgris;
int rang;
} fpixel;
static fpixel pixels[9];
/* --------------------------------------------------------------------- !*/
static int comparaison(const void *A, const void *B)
{
return ((fpixel *)A)->fgris > ((fpixel *)B)->fgris;
}
/* --------------------------------------------------------------------- !*/
/*
* this is a klugy approch, sorry.
*/
int fimg_filtre_morpho_0(FloatImg *sfimg, FloatImg *dfimg, int index)
{
int xs, ys, loop9;
int xp, yp;
float rgb[3], fval;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, sfimg, dfimg, index);
#endif
if ( (index<0) || (index>8)) {
fprintf(stderr, " %s: bad index %d\n", __func__, index);
#if MUST_ABORT
fflush(stderr); abort();
#endif
return -1;
}
fimg_clear(dfimg);
for (ys=1; ys<sfimg->height-1; ys++) {
for (xs=1; xs<sfimg->width-1; xs++) {
for (loop9=0; loop9<9; loop9++) {
xp = xs + deltas[loop9].x;
yp = ys + deltas[loop9].y;
fimg_get_rgb(sfimg, xp, yp, rgb);
pixels[loop9].fgris = rgb[0];
pixels[loop9].rang = loop9;
}
qsort(&pixels, 9, sizeof(fpixel), comparaison);
rgb[0] = rgb[1] = rgb[2] = pixels[index].fgris;
fimg_put_rgb(dfimg, xs, ys, rgb);
}
}
return 0;
}
/* --------------------------------------------------------------------- !*/

View File

@ -50,7 +50,7 @@ for (x=0; x<fimg->width; x++) {
fimg_plot_rgb(fimg, x, y, fr, fg, fb); fimg_plot_rgb(fimg, x, y, fr, fg, fb);
} }
k = fimg->height / 4; k = (fimg->height / 4) + 20;
for (x=0; x<fimg->width; x++) { for (x=0; x<fimg->width; x++) {
val = ((double)x / (double)fimg->width) * dval; val = ((double)x / (double)fimg->width) * dval;
for (y=0; y<20; y++) { for (y=0; y<20; y++) {
@ -60,6 +60,24 @@ for (x=0; x<fimg->width; x++) {
// fprintf(stderr, " %6d %f\n", x, val); // fprintf(stderr, " %6d %f\n", x, val);
} }
k = (fimg->height / 4) + 90;
for (x=0; x<fimg->width; x++) {
val = ((x%8)<4) ? dval : 0.0;
for (y=0; y<20; y++) {
fimg_plot_rgb(fimg, x, k+y, val, val, val);
fimg_plot_rgb(fimg, x, k+y+20, dval-val, dval-val, dval-val);
}
}
k = (fimg->height / 4) + 140;
for (x=0; x<fimg->width; x++) {
for (y=0; y<20; y++) {
val = drand48() * dval;
fimg_plot_rgb(fimg, x, k+y, val, val, val);
fimg_plot_rgb(fimg, x, k+y+20, dval-val, dval-val, dval-val);
}
}
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -25,7 +25,8 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Displace, ReadPNG, Plasmas, Hilight, OpenEXR, Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
Geometrie, FileType, Mirror, KillRGB, Geometrie, FileType, Mirror, KillRGB,
Pixelize,SplitLevel, DecompRgbz, DecompRgbg, Pixelize,SplitLevel, DecompRgbz, DecompRgbg,
Rectangle, Dicom, Fakolor0, Fakolor3 }; Rectangle, Dicom, Fakolor0, Fakolor3,
Fmorpho0 };
typedef struct { typedef struct {
char *name; char *name;
int Cmd; int Cmd;
@ -62,6 +63,7 @@ Command commands[] = {
{ "dicom", Dicom }, { "dicom", Dicom },
{ "fakolor0", Fakolor0 }, { "fakolor0", Fakolor0 },
{ "fakolor3", Fakolor3 }, { "fakolor3", Fakolor3 },
{ "fmorpho0", Fmorpho0 },
{ NULL, 0 } { NULL, 0 }
} ; } ;
@ -99,13 +101,17 @@ fprintf(stderr, "options:\n");
fprintf(stderr, "\t-k 1.414\tset float value\n"); fprintf(stderr, "\t-k 1.414\tset float value\n");
fprintf(stderr, "\t-l\t\tlist tests\n"); fprintf(stderr, "\t-l\t\tlist tests\n");
fprintf(stderr, "\t-o \t\toutfile\n"); fprintf(stderr, "\t-o \t\toutfile\n");
fprintf(stderr, "\t-v \t\tincrease verbosity\n");
if (verbosity) {
fprintf(stderr, "commands:\n"); fprintf(stderr, "commands:\n");
pcmd = commands; pcmd = commands;
while (pcmd->name) { while (pcmd->name) {
fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd); fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd);
pcmd++; pcmd++;
} }
}
fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n"); fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n");
if (k) fimg_print_version(k); if (k) fimg_print_version(k);
@ -253,6 +259,9 @@ switch(opt) {
case Fakolor0: case Fakolor0:
foo = essai_0_fausses_couleurs(outfile, 0); foo = essai_0_fausses_couleurs(outfile, 0);
break; break;
case Fmorpho0:
foo = essai_fmorpho_0(filename, "/tmp/fmorpho", 0);
break;
default: default:
fprintf(stderr, "'%s' is a bad command\n", command); fprintf(stderr, "'%s' is a bad command\n", command);
exit(1); exit(1);

View File

@ -1,4 +1,7 @@
/* /*
* FLOATIMG
* --------
* tests des fonctions diverses - subroutines * tests des fonctions diverses - subroutines
see also: t.c see also: t.c
*/ */
@ -17,6 +20,70 @@
extern int verbosity; extern int verbosity;
#define W 1024
#define H 768
/* --------------------------------------------------------------------- */
/*
* nouveau 30 octobre 2022 --> fmorpho.c
*/
int essai_fmorpho_0(char *infile, char *basefname, int k)
{
FloatImg src, dst;
int idx, foo;
char fname[100];
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__, infile, basefname, k);
if (k) {
fprintf(stderr, "%s k=%d must be 0\n", __func__, k);
return -6;
}
if (NULL == infile ) {
foo = fimg_create(&src, W, H, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s: create -> %d\n",__func__, foo);
return foo;
}
foo = fimg_test_pattern(&src, 0, 254.99);
if (foo) {
fprintf(stderr, "%s: test_pattern -> %d\n",__func__, foo);
return foo;
}
}
else {
foo = fimg_create_from_dump(infile, &src);
if (foo) {
fprintf(stderr, "%s: error %d loading '%s'\n", __func__, foo, infile);
return foo;
}
}
fimg_save_as_pnm(&src, "foo.pnm", 0);
foo = fimg_clone(&src, &dst, 0);
if (foo) {
fprintf(stderr, "%s: clone -> %d\n",__func__, foo);
return foo;
}
for (idx=0; idx<9; idx++) {
sprintf(fname, "%s%04d.pnm", basefname, idx);
fprintf(stderr, " ---> %s\n", fname);
foo = fimg_filtre_morpho_0(&src, &dst, idx);
if (foo) {
fprintf(stderr, "%s: got a %d at round %d\n", __func__, foo, idx);
return foo;
}
fimg_save_as_pnm(&dst, fname, 0);
}
fimg_destroy(&src); fimg_destroy(&dst);
return 0;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* nouveau 18 mai 2022 */ /* nouveau 18 mai 2022 */
int essai_0_fausses_couleurs(char *dstfile, int type) int essai_0_fausses_couleurs(char *dstfile, int type)
@ -24,8 +91,6 @@ int essai_0_fausses_couleurs(char *dstfile, int type)
FloatImg src, dst; FloatImg src, dst;
int foo; int foo;
#define W 1024
#define H 768
fprintf(stderr, "\nEssais fausses couleurs (type %d) -> '%s'\n", type, dstfile); fprintf(stderr, "\nEssais fausses couleurs (type %d) -> '%s'\n", type, dstfile);
foo = fimg_create(&src, W, H, FIMG_TYPE_RGB); foo = fimg_create(&src, W, H, FIMG_TYPE_RGB);

View File

@ -34,6 +34,7 @@ int essai_lecture_png(char *fname, char *outfile, int notused);
int essai_highlights(char *inf, char *outf, int ikoef, float fkoef); int essai_highlights(char *inf, char *outf, int ikoef, float fkoef);
int essai_openexr(char *inf, char *outf, int flags); int essai_openexr(char *inf, char *outf, int flags);
int essai_fmorpho_0(char *infile, char *basefname, int k);
int essai_pixelize(char *infile, char *outfile); int essai_pixelize(char *infile, char *outfile);

View File

@ -144,7 +144,7 @@ for (idx=0; idx<4; idx++) {
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
/* d'après Wikipedia Fr : /* d'apres Wikipedia Fr :
| c = 0 | c = 0
| s = x1 | s = x1
| pour j de 2 à n | pour j de 2 à n