2022-11-01 19:35:40 +11:00
|
|
|
/*
|
|
|
|
* 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>
|
2023-01-21 10:07:21 +11:00
|
|
|
|
|
|
|
#include "../floatimg.h"
|
2022-11-01 19:35:40 +11:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- !*/
|
|
|
|
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];
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- !*/
|
2022-11-03 08:11:54 +11:00
|
|
|
static int comparaison_fgris(const void *A, const void *B)
|
2022-11-01 19:35:40 +11:00
|
|
|
{
|
|
|
|
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;
|
2022-11-03 08:11:54 +11:00
|
|
|
float rgb[3];
|
2022-11-01 19:35:40 +11:00
|
|
|
|
2023-01-31 10:14:56 +11:00
|
|
|
#if DEBUG_LEVEL
|
2022-11-01 19:35:40 +11:00
|
|
|
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, sfimg, dfimg, index);
|
2023-01-31 10:14:56 +11:00
|
|
|
#endif
|
2022-11-01 19:35:40 +11:00
|
|
|
|
|
|
|
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);
|
2023-01-31 10:14:56 +11:00
|
|
|
pixels[loop9].fgris = rgb[0] + rgb[1] + rgb[2];
|
2022-11-01 19:35:40 +11:00
|
|
|
pixels[loop9].rang = loop9;
|
|
|
|
}
|
2022-11-03 08:11:54 +11:00
|
|
|
qsort(&pixels, 9, sizeof(fpixel), comparaison_fgris);
|
2022-11-01 19:35:40 +11:00
|
|
|
rgb[0] = rgb[1] = rgb[2] = pixels[index].fgris;
|
|
|
|
fimg_put_rgb(dfimg, xs, ys, rgb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- !*/
|