Compare commits

...

6 Commits

Author SHA1 Message Date
tTh 3bd387f0a9 tuning of the "normalize" option 2023-10-18 16:08:51 +02:00
tTh 085e19942a cosmetic 2023-10-10 23:51:56 +02:00
tTh 152beddcb7 fimg2text can now add column names 2023-10-09 10:48:39 +02:00
tTh c1b6f9ae40 cosmetic 2023-10-09 03:13:50 +02:00
tTh 2c407e5dd9 silent a message 2023-10-08 10:26:03 +02:00
tTh c6b75d3bba working on lowpass filter 2023-10-08 09:38:42 +02:00
8 changed files with 131 additions and 44 deletions

View File

@ -20,7 +20,7 @@
* https://git.tetalab.org/tTh/FloatImg
*/
#define FIMG_VERSION (229)
#define FIMG_VERSION (230)
#define RELEASE_NAME ("noname")
#define PATCH_LEVEL ("aaaa")

View File

@ -29,12 +29,12 @@ fprintf(stderr, "%8.3f %8.3f %8.3f\n", M[6], M[7], M[8]);
sum = 0.0;
for (idx=0; idx<9; idx++) sum += M[idx];
fprintf(stderr, " sum %8.3f\n", sum);
fprintf(stderr, " mult %8.3f\n", filtr->mult);
fprintf(stderr, " offset %8.3f\n", filtr->offset);
fprintf(stderr, " sum: %8.3f\n", sum);
fprintf(stderr, " mult: %8.3f\n", filtr->mult);
fprintf(stderr, " offset: %8.3f\n", filtr->offset);
value = (sum * filtr->mult) + filtr->offset;
fprintf(stderr, " value %8.3f ???\n", value);
fprintf(stderr, " value: %8.3f\n", value);
return 0;
}
@ -46,9 +46,9 @@ float *pr, *pg, *pb; /* alias for src pix filds */
float *M; /* alias of filter matrix */
double dval;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, filtr);
#endif
// #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, filtr);
// #endif
if (src->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: src type %d invalid\n", __func__, src->type);
@ -59,12 +59,12 @@ if (dst->type != FIMG_TYPE_RGB) {
return -99;
}
if (fimg_images_not_compatible(src, dst)) {
fprintf(stderr, "%s: src & dst not comatibles\n", __func__);
fprintf(stderr, "%s: src & dst not compatibles\n", __func__);
return -98;
}
if (verbosity > 1) {
fimg_show_filter(__func__, filtr);
fimg_show_filter((char *)__func__, filtr);
}
/* aliasing some vars for cleaner code */
@ -73,9 +73,7 @@ w = src->width; h = src->height;
M = filtr->matrix;
for (y=1; y < h-1; y++) {
for (x=1; x < w-1; x++) {
of = x + (y * w);
dval = M[0] * pr[of-(w+1)] +
@ -142,9 +140,7 @@ if (img->type != FIMG_TYPE_RGB) {
pr = img->R; pg = img->G; pb = img->B;
for (y=1; y < img->height-1; y++) {
for (x=1; x < img->width-1; x++) {
offset = x + (y * img->width);
cr = pr[offset] + pr[offset+1] +
@ -159,7 +155,6 @@ for (y=1; y < img->height-1; y++) {
pr[offset] = cr / 4.0;
pg[offset] = cg / 4.0;
pb[offset] = cb / 4.0;
}
}
@ -237,6 +232,9 @@ return foo;
}
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/*
* XXX inplace filtering is a BAD IDEA
*/
int fimg_lissage_3x3(FloatImg *img)
{
int foo;
@ -265,6 +263,13 @@ if (foo) {
fprintf(stderr, "%s: lowpass -> %d\n", __func__, foo);
abort();
}
foo = fimg_copy_data(&tmp, img);
if (foo) {
fprintf(stderr, "%s: copy data -> %d\n", __func__, foo);
abort();
}
foo = fimg_destroy(&tmp);
if (foo) {
fprintf(stderr, "%s: destroy -> %d\n", __func__, foo);

View File

@ -8,7 +8,7 @@ cp tools/mkfimg tools/fimg2pnm tools/fimgops \
tools/png2fimg tools/fimgstats tools/fimgfx \
tools/cumulfimgs tools/fimg2text \
tools/fimghalfsize \
tools/fimgmetadata \
tools/fimgmetadata tools/fimgfilters \
tools/fimgextract \
/usr/local/bin

View File

@ -116,7 +116,9 @@ int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval)
int nbre, idx;
double dval;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %g )\n", __func__, s, d, maxval);
#endif
if (s->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: type %d invalide\n",

View File

@ -21,14 +21,10 @@ int x, y;
float rgb[3];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( %p '%s' %d )\n", __func__,
fprintf(stderr, ">>> %s ( %p '%s' 0x%x )\n", __func__,
src, fname, flags);
#endif
if (0 != flags) {
fprintf(stderr, "bad flags in %s\n", __func__);
}
fp = NULL; /* molly guard */
if (strcmp("-", fname)) { /* real file */
fprintf(stderr, "real file '%s'\n", fname);
@ -38,6 +34,12 @@ else {
}
fp = stdout; /* XXX */
/*
* put a first line, so we can load those data with R
*/
if (flags & 1) { fputs("X Y R G B\n", fp); }
for (y=0; y<src->height; y+=steps) {
for (x=0; x<src->width; x+=steps) {
fimg_get_rgb(src, x, y, rgb);
@ -49,6 +51,9 @@ for (y=0; y<src->height; y+=steps) {
return 0;
}
/* --------------------------------------------------------------------- */
/*
* This function must be in the libfloatimg !
*/
static int normalize(FloatImg *pimg, float vmax)
{
float mmv[6], maxi, coef;
@ -85,14 +90,15 @@ return 0;
}
/* --------------------------------------------------------------------- */
int convertir_fimg_en_machinable(char *srcname, char *dstname,
int steps, float norm)
int steps, float norm, int header)
{
int foo, infos[3];
int flg;
FloatImg fimg;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( '%s' '%s' %d %f )\n", __func__,
srcname, dstname, steps, norm);
fprintf(stderr, ">>> %s ( '%s' '%s' %d %f %d )\n", __func__,
srcname, dstname, steps, norm, header);
#endif
if (steps < 1) {
@ -100,12 +106,14 @@ if (steps < 1) {
exit(1);
}
flg = 0;
if (header) flg |= 1;
foo = fimg_fileinfos(srcname, infos);
if (foo) {
fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo);
return foo;
}
if (verbosity) {
fprintf(stderr, "%s: image '%s' is %d x %d %s\n",
__func__,
@ -119,16 +127,12 @@ if (foo) {
return -1;
}
if (verbosity) {
// fimg_describe(&fimg, srcname);
fprintf(stderr, "normalize to %f\n", norm);
}
if (norm > 0.0) {
// fprintf(stderr, "normalize %p\n", &fimg);
if (verbosity) fprintf(stderr, "normalize to %f\n", norm);
foo = normalize(&fimg, norm);
}
foo = export_as_machinable(&fimg, dstname, steps, 0);
foo = export_as_machinable(&fimg, dstname, steps, flg);
if (foo) {
fprintf(stderr,"%s: err %d on export\n", __func__, foo);
}
@ -141,9 +145,10 @@ void help(int k)
{
puts("usage:\n\tfimg2text [options] foo.fimg > bar.csv");
puts("options:");
puts("\t-v\t\tincrease verbosity");
puts("\t-n 3.14\t\tnormalize picture");
puts("\t-n Value\tnormalize picture if Value > 0.0");
puts("\t-s N\t\tsteps on x & y");
puts("\t-T\t\tadd header with colon name");
puts("\t-v\t\tincrease verbosity");
if (verbosity) {
printf("*** compiled: %s at %s\n", __DATE__, __TIME__);
fimg_print_version(k);
@ -156,15 +161,17 @@ int main(int argc, char *argv[])
{
int foo, opt;
int steps = 1;
float norm_val = 222.0; /* < 0 : don't normalize */
int header = 0;
float norm_val = -1; /* < 0 : don't normalize */
// char separator = ' ';
while ((opt = getopt(argc, argv, "f:hn:s:v")) != -1) {
while ((opt = getopt(argc, argv, "f:hn:s:Tv")) != -1) {
switch(opt) {
// case 'f': separator = optarg[0]; break;
case 'v': verbosity++; break;
case 'h': help(1); exit(1);
case 's': steps = atoi(optarg); break;
case 'T': header = 1; break;
case 'n': norm_val = atof(optarg); break;
default: exit(1);
}
@ -175,7 +182,8 @@ if (1 != argc-optind) {
exit(1);
}
foo = convertir_fimg_en_machinable(argv[optind], "-", steps, norm_val);
foo = convertir_fimg_en_machinable(argv[optind], "-",
steps, norm_val, header);
if (foo) {
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
return 1;

78
tools/fimgfilters.c Normal file
View File

@ -0,0 +1,78 @@
/*
FIMGFILTERS
===========
new: Sun Oct 8 05:51:05 UTC 2023
*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include "../floatimg.h"
int verbosity;
/* --------------------------------------------------------------------- */
int filtre_image(char *infname, char *outfname)
{
FloatImg src, dst;
int foo;
static FimgFilter3x3 filtre = {
{
2.0, 3.0, 2.0,
3.0, 4.0, 3.0,
2.0, 3.0, 2.0,
},
1.0/24.0, 0.0
};
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, infname, outfname);
fimg_show_filter(NULL, &filtre);
if ((foo = fimg_create_from_dump(infname, &src))) {
fprintf(stderr, "read error on '%s' is %d\n", infname, foo);
exit(2);
}
if ((foo = fimg_clone(&src, &dst, 0))) {
fprintf(stderr, "clone error on %p is %d\n", &src, foo);
exit(3);
}
foo = fimg_filter_3x3(&src, &dst, &filtre);
if (foo) {
fprintf(stderr, "%s: filtre -> %d\n", __func__, foo);
exit(4);
}
foo = fimg_dump_to_file(&dst, outfname, 0);
if (foo) {
fprintf(stderr, "dumping to file give us a %d\n", foo);
}
return -12;
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
if (3 != argc) {
fprintf(stderr, "usage: %s in.fimg out.fimg\n", argv[0]);
exit(1);
}
fprintf(stderr, " +++ %s +++\n", argv[0]);
foo = filtre_image(argv[1], argv[2]);
fprintf(stderr, " filtrage -> %d\n", foo);
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -39,7 +39,7 @@ int foo;
float vals[6];
if (verbosity) {
fprintf(stderr, "%s numbers from %p :\n", __func__, fimg);
fprintf(stderr, "%s from %p :\n", __func__, fimg);
}
fimg_printhead(fimg);

View File

@ -128,7 +128,7 @@ for (foo=0; foo<argc; foo++)
#endif
if (type < 0) {
fprintf(stderr, "type '%s' is unknow\n", tname);
fprintf(stderr, "%s: type '%s' is unknow\n", argv[0], tname);
exit(2);
}
@ -153,12 +153,6 @@ switch (nbargs) {
fname = argv[optind];
if (verbosity>1) {
fprintf(stderr, "*** mkfimg *** %s %s *** pid %ld\n",
__DATE__, __TIME__, (long)getpid());
fimg_print_version(0);
}
if (verbosity) fprintf(stderr, "::: %s is making '%s' %dx%d, type %d\n",
argv[0], fname, width, height, type);