Compare commits

..

3 Commits

Author SHA1 Message Date
tTh
56073c0c80 new func: fimg_do_stripes(&fimg, 0); 2022-09-19 11:58:30 +02:00
tTh
eedc9197db are real numbers evil ? 2022-09-19 11:17:24 +02:00
tTh
feafd2799d a new "rescale" option in cumulfimgs 2022-09-17 19:18:45 +02:00
6 changed files with 112 additions and 28 deletions

View File

@ -20,7 +20,7 @@
* https://git.tetalab.org/tTh/FloatImg * https://git.tetalab.org/tTh/FloatImg
*/ */
#define FIMG_VERSION (198) #define FIMG_VERSION (202)
#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 */
@ -233,7 +233,7 @@ int fimg_qsort_rgb_b(FloatImg *psrc, FloatImg *pdst, int notused);
/* module funcs/equalize.c */ /* module funcs/equalize.c */
int fimg_equalize_compute(FloatImg *src, void *vptr, float vmax); int fimg_equalize_compute(FloatImg *src, void *vptr, float vmax);
int fimg_equalize(FloatImg *src, float vmax); int fimg_equalize(FloatImg *src, double vmax);
int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k); int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k);
int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused); int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused);
@ -254,6 +254,7 @@ int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags);
/* module funcs/rampes.c */ /* module funcs/rampes.c */
int fimg_hdeg_a(FloatImg *img, double dcoef); int fimg_hdeg_a(FloatImg *img, double dcoef);
int fimg_vdeg_a(FloatImg *img, double dcoef); int fimg_vdeg_a(FloatImg *img, double dcoef);
int fimg_do_stripes(FloatImg *img, int mode);
/* FIMG native file module */ /* FIMG native file module */
int fimg_fileinfos(char *fname, int *datas); int fimg_fileinfos(char *fname, int *datas);
@ -285,6 +286,7 @@ int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head); int fimg_to_gray(FloatImg *head);
int fimg_add_cste(FloatImg *fi, float value); int fimg_add_cste(FloatImg *fi, float value);
int fimg_mul_cste(FloatImg *fi, float value); int fimg_mul_cste(FloatImg *fi, float value);
int fimg_div_cste(FloatImg *fi, float value);
int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused); int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused);
int fimg_absolute(FloatImg *fimg); int fimg_absolute(FloatImg *fimg);
void fimg_drand48(FloatImg *fi, float kmul); void fimg_drand48(FloatImg *fi, float kmul);

View File

@ -16,9 +16,10 @@ extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* new func: Wed 14 Sep 2022 11:28:04 AM CEST /* new func: Wed 14 Sep 2022 11:28:04 AM CEST
*/ */
int fimg_equalize(FloatImg *src, float vmax) int fimg_equalize(FloatImg *src, double vmax)
{ {
float mm[6], maxi, coef; float mm[6];
double maxi, coef;
int foo; int foo;
#if DEBUG_LEVEL #if DEBUG_LEVEL
@ -31,8 +32,8 @@ if (foo) {
fprintf(stderr, "%s: err %d get_minmax\n", __func__, foo); fprintf(stderr, "%s: err %d get_minmax\n", __func__, foo);
return foo; return foo;
} }
maxi = mm[1] > mm[3] ? mm[1] : mm[3]; maxi = mm[1] > mm[3] ? (double)mm[1] : (double)mm[3];
maxi = maxi > mm[5] ? maxi : mm[5]; maxi = maxi > mm[5] ? maxi : (double)mm[5];
coef = vmax / maxi; coef = vmax / maxi;
if (verbosity) { if (verbosity) {
@ -41,7 +42,7 @@ if (verbosity) {
fprintf(stderr, "vmax %f maxi %f multcoef = %g\n", vmax, maxi, coef); fprintf(stderr, "vmax %f maxi %f multcoef = %g\n", vmax, maxi, coef);
} }
foo = fimg_mul_cste(src, coef); foo = fimg_mul_cste(src, (float)coef);
if (foo) { if (foo) {
fprintf(stderr, "%s: err %d mul_cste\n", __func__, foo); fprintf(stderr, "%s: err %d mul_cste\n", __func__, foo);
return foo; return foo;

View File

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include "../floatimg.h" #include "../floatimg.h"
@ -23,8 +24,7 @@ if (FIMG_TYPE_RGB != img->type) {
fprintf(stderr, "%s bad type\n", __func__); fprintf(stderr, "%s bad type\n", __func__);
return -6; return -6;
} }
for (x=0; x<img->width; x++) for (x=0; x<img->width; x++) {
{
value = (float)x / (float)img->width; value = (float)x / (float)img->width;
value *= dcoef; value *= dcoef;
for (y=0; y<img->height; y++) { for (y=0; y<img->height; y++) {
@ -51,11 +51,10 @@ if (FIMG_TYPE_RGB != img->type) {
fprintf(stderr, "%s bad type\n", __func__); fprintf(stderr, "%s bad type\n", __func__);
return -6; return -6;
} }
for (y=0; y<img->height; y++)
{
value = (float)y / (float)img->height;
value *= dcoef;
for (x=0; x<img->width; x++) { for (x=0; x<img->width; x++) {
value = (float)x / (float)img->width;
value *= dcoef;
for (y=0; y<img->height; y++) {
fimg_plot_rgb(img, x, y, value, value, value); fimg_plot_rgb(img, x, y, value, value, value);
} }
} }
@ -63,3 +62,47 @@ for (y=0; y<img->height; y++)
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* nouveau 19 septembre 2022 */
int fimg_do_stripes(FloatImg *img, int mode)
{
int x, y, quad;
float *ligne;
float fr, fg, fb;
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, img, mode);
/*
* allocate and fill a lookup table
*/
if (NULL==(ligne=malloc(img->width*sizeof(float)))) {
fprintf(stderr, "%s: malloc fail\n", __func__);
exit(1);
}
for (x=0; x<img->width; x++)
ligne[x] = (float)x / (float)img->width;
/*
* build the pixels
*/
for (y=0; y<img->height; y++)
{
quad = (y*4) / img->height ;
for (x=0; x<img->width; x++) {
fr = fg = fb = ligne[x];
switch(quad) {
case 0: fg = fb = 0; break;
case 1: fr = fb = 0; break;
case 2: fr = fg = 0; break;
case 3: break;
default: abort(); break;
}
fimg_plot_rgb(img, x, y, fr, fg, fb);
}
}
free(ligne);
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -296,6 +296,33 @@ if (fi->type == FIMG_TYPE_GRAY) {
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
/* nouveau 17 septembre 2022 */
int fimg_div_cste(FloatImg *fi, float value)
{
int nbre, idx;
if ( (fi->type != FIMG_TYPE_RGB) && (fi->type != FIMG_TYPE_GRAY) ) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return -44;
}
nbre = fi->width * fi->height;
if (fi->type == FIMG_TYPE_RGB) {
for (idx=0; idx<nbre; idx++) {
fi->R[idx] /= value;
fi->G[idx] /= value;
fi->B[idx] /= value;
}
}
if (fi->type == FIMG_TYPE_GRAY) {
for (idx=0; idx<nbre; idx++) {
fi->R[idx] /= value;
}
}
return 0;
}
/* ---------------------------------------------------------------- */
/* /*
* oh, please explain the usecase of this function ! * oh, please explain the usecase of this function !
*/ */

View File

@ -40,9 +40,10 @@ void help(int v)
puts(""); puts("");
puts("$ cumulfimgs a.fimg b.fimg c-fimg ..."); puts("$ cumulfimgs a.fimg b.fimg c-fimg ...");
puts("cumulator options :"); puts("cumulator options :");
puts("\t-v\tincrease verbosity");
puts("\t-o\tname of output file");
puts("\t-g\tconvert to gray level"); puts("\t-g\tconvert to gray level");
puts("\t-o\tname of output file");
puts("\t-s\trescale end image");
puts("\t-v\tincrease verbosity");
puts(""); puts("");
if (verbosity) { puts("Xperiment"); fimg_print_version(v); } if (verbosity) { puts("Xperiment"); fimg_print_version(v); }
exit(0); exit(0);
@ -52,22 +53,25 @@ int main(int argc, char *argv[])
{ {
int foo, idx; int foo, idx;
int opt; int opt;
int compte = 0;
int compte = 0;
int to_gray = 0; int to_gray = 0;
int experiment = 0; int experiment = 0;
int rescale = 0;
int src_loaded = 0;
char *output_file = "out.fimg"; char *output_file = "out.fimg";
FloatImg accu, temp; FloatImg accu, temp;
int src_loaded = 0;
float vals[6]; float vals[6];
g_width = g_height = 0; g_width = g_height = 0;
while ((opt = getopt(argc, argv, "gho:vx")) != -1) { while ((opt = getopt(argc, argv, "gho:svx")) != -1) {
switch(opt) { switch(opt) {
case 'g': to_gray = 1; break; case 'g': to_gray = 1; break;
case 'h': help(1); break; case 'h': help(1); break;
case 'o': output_file = optarg; break; case 'o': output_file = optarg; break;
case 's': rescale = 1; break;
case 'v': verbosity++; break; case 'v': verbosity++; break;
case 'x': experiment++; break; case 'x': experiment++; break;
} }
@ -104,6 +108,11 @@ for (idx=optind; idx<argc; idx++) {
compte++; compte++;
} }
if (rescale) {
fprintf(stderr, "cumulfimg: count = %d\n", compte);
fimg_div_cste(&accu, (float)compte);
}
/* XXX */ /* XXX */
if (experiment) { if (experiment) {

View File

@ -154,8 +154,8 @@ fname = argv[optind];
if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s *** pid %ld\n", if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s *** pid %ld\n",
__DATE__, __TIME__, (long)getpid()); __DATE__, __TIME__, (long)getpid());
if (verbosity) fprintf(stderr, "making '%s' %dx%d, type %d\n", if (verbosity) fprintf(stderr, "::: %s is making '%s' %dx%d, type %d\n",
fname, width, height, type); argv[0], fname, width, height, type);
srand48(getpid() ^ time(NULL)); srand48(getpid() ^ time(NULL));
@ -176,6 +176,7 @@ switch(type) {
case T_TPAT0: fimg_test_pattern(&fimg, 0, fvalue); break; case T_TPAT0: fimg_test_pattern(&fimg, 0, fvalue); break;
case T_MIRCOL1: fimg_mircol_1(&fimg, fvalue); break; case T_MIRCOL1: fimg_mircol_1(&fimg, fvalue); break;
case T_BLOUP: fimg_draw_something(&fimg); break; case T_BLOUP: fimg_draw_something(&fimg); break;
case T_STRIPES: fimg_do_stripes(&fimg, 0); break;
case -1: exit(1); case -1: exit(1);
} }
@ -191,8 +192,9 @@ if (wrmdata) {
else { else {
foo = fimg_dump_to_file(&fimg, fname, 0); foo = fimg_dump_to_file(&fimg, fname, 0);
} }
if (foo) { if (foo) {
fprintf(stderr, "dump fimg to %s error -> %d\n", fname, foo); fprintf(stderr, "*** dump fimg to %s error -> %d\n", fname, foo);
exit(1); exit(1);
} }