new: 3x3 smoother in crapulator

This commit is contained in:
tonton th 2020-12-03 11:47:44 +01:00
parent 8f29cb0db0
commit 160a4afe7b
3 changed files with 45 additions and 15 deletions

View File

@ -37,7 +37,6 @@ FloatImg img;
int retval; int retval;
fimg_clone(pimg, &img, 0); fimg_clone(pimg, &img, 0);
// XXX fimg_clear(&img);
retval = fimg_contour_2x2(pimg, &img, 0); retval = fimg_contour_2x2(pimg, &img, 0);
if (retval) { if (retval) {
fprintf(stderr, "%s : err contour %d\n", fprintf(stderr, "%s : err contour %d\n",
@ -50,19 +49,43 @@ fimg_destroy(&img);
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
static int insitu_filtre3x3(FloatImg *pimg)
{
FloatImg img;
int retval;
FimgFilter3x3 filtre = {
{
1.0, 2.0, 1.0,
2.0, 4.0, 2.0,
1.0, 2.0, 1.0,
},
16.0, 0.0
};
fimg_clone(pimg, &img, 0);
retval = fimg_filter_3x3(pimg, &img, &filtre);
if (retval) {
fprintf(stderr, "%s error %d on filter\n", __func__, retval);
exit(1);
}
fimg_copy_data(&img, pimg);
fimg_destroy(&img);
return retval;
}
/* -------------------------------------------------------------- */
/* /*
* This is the main filter engine * This is the main filter engine
* used both for input and output * used both for input and output
*/ */
#define DEBUG_THIS_CRAP 1 #define DEBUG_THIS_CRAP 0
int crapulator(FloatImg *image, int idFx, float fval) int crapulator(FloatImg *image, int idFx, float fval)
{ {
int retval; int retval;
// FloatImg imgtmp; // FloatImg imgtmp;
static int count = 0;
int flag_debug = 0;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__, fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
@ -72,6 +95,8 @@ fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
retval = 0; retval = 0;
#if DEBUG_THIS_CRAP #if DEBUG_THIS_CRAP
static int count = 0;
int flag_debug = 0;
if (666==count) { if (666==count) {
flag_debug = 1; flag_debug = 1;
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__); fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
@ -112,10 +137,6 @@ switch (idFx) {
break; break;
case 9: case 9:
retval = fimg_classif_trial(image, image, 0.37, 0); retval = fimg_classif_trial(image, image, 0.37, 0);
if (retval) {
fprintf(stderr, "err %d in classif\n", retval);
exit(1);
}
break; break;
case 10: case 10:
retval = binarize(image, 0); retval = binarize(image, 0);
@ -126,6 +147,9 @@ switch (idFx) {
case 12: case 12:
retval = fimg_lissage_2x2(image); retval = fimg_lissage_2x2(image);
break; break;
case 13:
retval = insitu_filtre3x3(image);
break;
case 24: /* experiment ! */ case 24: /* experiment ! */
retval = des_bords_sombres_a(image, 160); retval = des_bords_sombres_a(image, 160);
break; break;
@ -146,9 +170,8 @@ if (flag_debug) {
fimg_save_as_png(image, "crap_after.png", 0); fimg_save_as_png(image, "crap_after.png", 0);
flag_debug = 0; flag_debug = 0;
} }
#endif
count++; count++;
#endif
return retval; return retval;
} }

View File

@ -99,7 +99,7 @@ fprintf(stderr, "glob '%s' -> %d, %ld files found\n", pattern, foo,
/* get the size of the inputs images */ /* get the size of the inputs images */
foo = fimg_fileinfos(globbuf.gl_pathv[0], datas); foo = fimg_fileinfos(globbuf.gl_pathv[0], datas);
width = datas[0]; height = datas[1]; width = datas[0]; height = datas[1];
fprintf(stderr, "image size %dx%d\n", width, height); fprintf(stderr, "first image size %dx%d\n", width, height);
fimg_create(&input, width, height, 3); fimg_create(&input, width, height, 3);
@ -111,7 +111,7 @@ if (foo) {
exit(1); exit(1);
} }
maxvalue = fimg_get_maxvalue(&input); maxvalue = fimg_get_maxvalue(&input);
fprintf(stderr, "maxvalue %f\n", maxvalue); fprintf(stderr, "first image maxvalue %f\n", maxvalue);
foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB); foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB);
fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo); fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);

View File

@ -6,8 +6,6 @@
#include "../floatimg.h" #include "../floatimg.h"
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr) int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr)
{ {
@ -20,6 +18,15 @@ double dval;
fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, src, dst, filtr); fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, src, dst, filtr);
#endif #endif
if (src->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: src type %d invalid\n", __func__, src->type);
return -99;
}
if (dst->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: dst type %d invalid\n", __func__, dst->type);
return -99;
}
/* aliasing some vars for cleaner code */ /* aliasing some vars for cleaner code */
pr = src->R; pg = src->G; pb = src->B; pr = src->R; pg = src->G; pb = src->B;
w = src->width; h = src->height; w = src->width; h = src->height;
@ -69,7 +76,7 @@ for (y=1; y < h-1; y++) {
} }
} }
return -1; return 0;
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* /*