substitute prefix il to il_

This commit is contained in:
2024-02-02 10:41:40 +03:00
parent f3570498e1
commit ec18c69732
15 changed files with 382 additions and 362 deletions

View File

@@ -25,27 +25,27 @@ int main(int argc, char **argv){
fprintf(stderr, "Usage: %s filename - open bw image file, equalize histogram, plot two crosses ans save as output.jpg\n", argv[0]);
return 1;
}
ilImage *I = ilImage_read(argv[1]);
il_Image *I = il_Image_read(argv[1]);
if(!I){
fprintf(stderr, "Can't read %s\n", argv[1]);
return 2;
}
int w = I->width, h = I->height;
double t0 = dtime();
uint8_t *eq = ilequalize8(I, 3, 0.1);
uint8_t *eq = il_equalize8(I, 3, 0.1);
green("Equalize: %g ms\n", (dtime() - t0)*1e3);
ilImage_free(&I);
il_Image_free(&I);
if(!eq) return 3;
ilImg3 *I3 = MALLOC(ilImg3, 1);
il_Img3 *I3 = MALLOC(il_Img3, 1);
I3->data = eq;
I3->height = h;
I3->width = w;
ilPattern *cross = ilPattern_xcross(25, 25);
ilImg3_drawpattern(I3, cross, 30, 30, ilColor_red);
ilImg3_drawpattern(I3, cross, 150, 50, ilColor_green);
ilPattern_free(&cross);
int ret = ilImg3_jpg("output.jpg", I3, 95);
ilImg3_free(&I3);
il_Pattern *cross = il_Pattern_xcross(25, 25);
il_Img3_drawpattern(I3, cross, 30, 30, il_Color_red);
il_Img3_drawpattern(I3, cross, 150, 50, il_Color_green);
il_Pattern_free(&cross);
int ret = il_Img3_jpg("output.jpg", I3, 95);
il_Img3_free(&I3);
if(!ret) return 4;
printf("File 'output.jpg' ready\n");
return 0;

View File

@@ -44,20 +44,20 @@ int main(int argc, char **argv){
if(w < 1 || h < 1) ERRX("Wrong image size");
if(xsigma < DBL_EPSILON || ysigma < DBL_EPSILON) ERRX("STD should be >0");
if(Niter < 1) ERRX("Iteration number should be a large positive number");
ilImage *I = ilImage_new(w, h, IMTYPE_U8);
il_Image *I = il_Image_new(w, h, IMTYPE_U8);
if(!I) ERRX("Can't create image %dx%d pixels", w, h);
int hits = 0;
for(int i = 0; i < Niter; ++i){
//int x = (int)ilNormal(x0, sigma), y = (int)ilNormal(y0, sigma);
double x, y;
ilNormalPair(&x, &y, x0, y0, xsigma, ysigma);
il_NormalPair(&x, &y, x0, y0, xsigma, ysigma);
if(x < 0 || x >= I->width || y < 0 || y >= I->height) continue;
uint8_t *pix = I->data + (int)x + ((int)y)*I->width;
if(*pix < 255) ++*pix;
++hits;
}
int ret = ilwrite_png(outp, I->width, I->height, 1, I->data);
ilImage_free(&I);
int ret = il_write_png(outp, I->width, I->height, 1, I->data);
il_Image_free(&I);
if(!ret) return 1;
printf("File %s ready; %d hits of %d\n", outp, hits, Niter);
return 0;

View File

@@ -25,7 +25,7 @@ static int w = 1024, h = 1024, help = 0;
static double fwhm = 3.5, beta = 1., lambda = 10.;
static char *outp = "output.jpg", *inp = NULL;
static ilPattern *star = NULL, *cross = NULL;
static il_Pattern *star = NULL, *cross = NULL;
static myoption cmdlnopts[] = {
{"help", NO_ARGS, NULL, '?', arg_int, APTR(&help), "show this help"},
@@ -58,21 +58,21 @@ static int getpars(const char *argv, int *x, int *y, int *a){
return TRUE;
}
static void addstar(ilImg3 *I, const char *str){
static void addstar(il_Img3 *I, const char *str){
int x, y, a;
if(!getpars(str, &x, &y, &a)) return;
printf("Add 'star' at %d,%d (ampl=%d)\n", x,y,a);
uint8_t c[3] = {a,a,a};
ilImg3_drawpattern(I, star, x, y, c);
il_Img3_drawpattern(I, star, x, y, c);
}
static void addcross(ilImg3 *I, const char *str){
static void addcross(il_Img3 *I, const char *str){
int x, y, a;
if(!getpars(str, &x, &y, &a)) return;
printf("Add 'cross' at %d,%d (ampl=%d)\n", x,y,a);
ilImg3_drawpattern(I, cross, x, y, ilColor_red);
il_Img3_drawpattern(I, cross, x, y, il_Color_red);
}
static void addfromfile(ilImg3 *I, void (*fn)(ilImg3*, const char*)){
static void addfromfile(il_Img3 *I, void (*fn)(il_Img3*, const char*)){
FILE *f = fopen(inp, "r");
if(!f){
WARN("Can't open %s", inp);
@@ -92,36 +92,36 @@ int main(int argc, char **argv){
if(help) showhelp(-1, cmdlnopts);
if(w < 1 || h < 1) ERRX("Wrong image size");
if(argc == 0 && inp == NULL) ERRX("Point at least one coordinate pair or file name");
ilImg3 *I = ilImg3_new(w, h);
il_Img3 *I = il_Img3_new(w, h);
if(!I) ERRX("Can't create image %dx%d pixels", w, h);
int par = (int)(fwhm*25.);
star = ilPattern_star(par, par, fwhm, beta);
cross = ilPattern_xcross(25, 25);
star = il_Pattern_star(par, par, fwhm, beta);
cross = il_Pattern_xcross(25, 25);
for(int i = 0; i < argc; ++i) addstar(I, argv[i]);
if(inp) addfromfile(I, addstar);
ilPattern_free(&star);
il_Pattern_free(&star);
double t0 = dtime();
ilImg3_addPoisson(I, lambda);
il_Img3_addPoisson(I, lambda);
green("Poisson noice took %gms\n", (dtime()-t0) * 1e3);
if(!ilImg3_jpg(outp, I, 95)) WARNX("Can't save %s", outp);
if(!il_Img3_jpg(outp, I, 95)) WARNX("Can't save %s", outp);
for(int i = 0; i < argc; ++i) addcross(I, argv[i]);
if(inp) addfromfile(I, addcross);
ilPattern_free(&cross);
il_Pattern_free(&cross);
uint8_t color[] = {255, 0, 100};
//uint8_t color[] = {0, 0, 0};
ilImg3_putstring(I, "Test string", 450, 520, color);
ilImg3_drawline(I, -10,900, 1600,1050, color);
ilImg3_drawcircle(I, 400,400, 500, color);
ilImg3_drawgrid(I, 0, 0, 100, 100, ilColor_green);
ilImg3_drawgrid(I, 0, 0, -20, -20, ilColor_blue);
ilImg3 *s = ilImg3_subimage(I, 100,-100, 899,1099);
il_Img3_putstring(I, "Test string", 450, 520, color);
il_Img3_drawline(I, -10,900, 1600,1050, color);
il_Img3_drawcircle(I, 400,400, 500, color);
il_Img3_drawgrid(I, 0, 0, 100, 100, il_Color_green);
il_Img3_drawgrid(I, 0, 0, -20, -20, il_Color_blue);
il_Img3 *s = il_Img3_subimage(I, 100,-100, 899,1099);
if(s){
ilImg3_jpg("outpsubimage.jpg", s, 95);
ilImg3_free(&s);
il_Img3_jpg("outpsubimage.jpg", s, 95);
il_Img3_free(&s);
}else WARNX("Bad subimage parameters");
int ret = ilImg3_jpg("crosses.jpg", I, 95);
//int ret = ilImg3_png(outp, I);
ilImg3_free(&I);
int ret = il_Img3_jpg("crosses.jpg", I, 95);
//int ret = il_Img3_png(outp, I);
il_Img3_free(&I);
if(!ret) return 4;
printf("File %s ready\n", outp);
return 0;

View File

@@ -25,7 +25,7 @@ static int w = 1024, h = 1024, help = 0;
static double fwhm = 3.5, beta = 1.;
static char *outp = "output.png", *inp = NULL;
static ilImage *star = NULL;
static il_Image *star = NULL;
static myoption cmdlnopts[] = {
{"help", NO_ARGS, NULL, '?', arg_int, APTR(&help), "show this help"},
@@ -57,15 +57,15 @@ static int getpars(const char *argv, int *x, int *y, double *w){
return TRUE;
}
static void addstar(ilImage *I, const char *str){
static void addstar(il_Image *I, const char *str){
int x, y;
double w;
if(!getpars(str, &x, &y, &w)) return;
printf("Add 'star' at %d,%d (weight=%g)\n", x,y,w);
ilImage_addsub(I, star, x, y, w);
il_Image_addsub(I, star, x, y, w);
}
static void addfromfile(ilImage *I){
static void addfromfile(il_Image *I){
FILE *f = fopen(inp, "r");
if(!f){
WARN("Can't open %s", inp);
@@ -85,30 +85,30 @@ int main(int argc, char **argv){
if(help) showhelp(-1, cmdlnopts);
if(w < 1 || h < 1) ERRX("Wrong image size");
if(argc == 0 && inp == NULL) ERRX("Point at least one coordinate pair or file name");
ilImage *I = ilImage_new(w, h, IMTYPE_U16);
il_Image *I = il_Image_new(w, h, IMTYPE_U16);
if(!I) ERRX("Can't create image %dx%d pixels", w, h);
int par = (int)(fwhm*25.);
star = ilImage_star(IMTYPE_U16, par, par, fwhm, beta);
star = il_Image_star(IMTYPE_U16, par, par, fwhm, beta);
if(!star) ERRX("Can't create 'star' pattern");
for(int i = 0; i < argc; ++i) addstar(I, argv[i]);
if(inp) addfromfile(I);
ilImage_free(&star);
ilImage_putstring(I, "Hello, world!!", -10, 10);
ilImage_putstring(I, "0", 0, 1016);
ilImage_putstring(I, "Hello, world.!?\"'\nMore again", 50, 500);
ilImage_putstring(I, "Hello, world!", 950, 1018);
il_Image_free(&star);
il_Image_putstring(I, "Hello, world!!", -10, 10);
il_Image_putstring(I, "0", 0, 1016);
il_Image_putstring(I, "Hello, world.!?\"'\nMore again", 50, 500);
il_Image_putstring(I, "Hello, world!", 950, 1018);
uint16_t v = 50000;
ilImage_drawline(I, -100,-1000, 1000, 1200, &v);
ilImage_drawcircle(I, 1000,1000, 1000, &v);
ilImage_drawcircle(I, 512,512, 512, &v);
il_Image_drawline(I, -100,-1000, 1000, 1200, &v);
il_Image_drawcircle(I, 1000,1000, 1000, &v);
il_Image_drawcircle(I, 512,512, 512, &v);
for(int _ = 0; _ < 1024; _ += 50){
char s[6];
snprintf(s, 6, "%d", _);
ilImage_putstring(I, s, _, 300);
il_Image_putstring(I, s, _, 300);
}
uint8_t *bytes = ilImage2u8(I, 1);
int ret = ilwrite_png(outp, I->width, I->height, 1, bytes);
ilImage_free(&I);
uint8_t *bytes = il_Image2u8(I, 1);
int ret = il_write_png(outp, I->width, I->height, 1, bytes);
il_Image_free(&I);
FREE(bytes);
if(!ret) return 4;
printf("File %s ready\n", outp);

View File

@@ -43,47 +43,47 @@ int main(int argc, char **argv){
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
if(!infile) ERRX("Point name of input file");
ilImage *I = ilImage_read(infile);
il_Image *I = il_Image_read(infile);
if(!I) ERR("Can't read %s", infile);
if(bg < 0. && !ilImage_background(I, &bg)) ERRX("Can't calculate background");
if(bg < 0. && !il_Image_background(I, &bg)) ERRX("Can't calculate background");
uint8_t ibg = (int)(bg + 0.5);
printf("Background level: %d\n", ibg);
int w = I->width, h = I->height, wh = w*h;
ilImage *Ibg = ilImage_sim(I);
il_Image *Ibg = il_Image_sim(I);
memcpy(Ibg->data, I->data, wh);
uint8_t *idata = (uint8_t*) Ibg->data;
for(int i = 0; i < wh; ++i) idata[i] = (idata[i] > ibg) ? idata[i] - ibg : 0;
if(outbg) ilwrite_jpg(outbg, Ibg->width, Ibg->height, 1, idata, 95);
if(outbg) il_write_jpg(outbg, Ibg->width, Ibg->height, 1, idata, 95);
double t0 = dtime();
uint8_t *Ibin = ilImage2bin(I, bg);
uint8_t *Ibin = il_Image2bin(I, bg);
if(!Ibin) ERRX("Can't binarize image");
green("Binarization: %gms\n", 1e3*(dtime()-t0));
if(neros > 0){
t0 = dtime();
uint8_t *eros = ilerosionN(Ibin, w, h, neros);
uint8_t *eros = il_erosionN(Ibin, w, h, neros);
FREE(Ibin);
Ibin = eros;
green("%d erosions: %gms\n", neros, 1e3*(dtime()-t0));
}
if(ndilat > 0){
t0 = dtime();
uint8_t *dilat = ildilationN(Ibin, w, h, ndilat);
uint8_t *dilat = il_dilationN(Ibin, w, h, ndilat);
FREE(Ibin);
Ibin = dilat;
green("%d dilations: %gms\n", ndilat, 1e3*(dtime()-t0));
}
if(outbin){
ilImage *tmp = ilbin2Image(Ibin, w, h);
ilwrite_jpg(outbin, tmp->width, tmp->height, 1, (uint8_t*)tmp->data, 95);
ilImage_free(&tmp);
il_Image *tmp = il_bin2Image(Ibin, w, h);
il_write_jpg(outbin, tmp->width, tmp->height, 1, (uint8_t*)tmp->data, 95);
il_Image_free(&tmp);
}
ilConnComps *comps;
il_ConnComps *comps;
t0 = dtime();
size_t *labels = ilCClabel4(Ibin, w, h, &comps);
size_t *labels = il_CClabel4(Ibin, w, h, &comps);
green("Labeling: %gms\n", 1e3*(dtime()-t0));
if(labels && comps->Nobj > 1){
printf("Detected %zd components\n", comps->Nobj-1);
ilBox *box = comps->boxes + 1;
il_Box *box = comps->boxes + 1;
for(size_t i = 1; i < comps->Nobj; ++i, ++box){
printf("\t%4zd: s=%d, LU=(%d, %d), RD=(%d, %d)\n", i, box->area, box->xmin, box->ymin, box->xmax, box->ymax);
}

View File

@@ -39,16 +39,16 @@ int main(int argc, char **argv){
if(help) showhelp(-1, cmdlnopts);
if(w < 1 || h < 1) ERRX("Wrong image size");
if(lambda < 1.) ERRX("LAMBDA should be >=1");
ilImage *I = ilImage_new(w, h, IMTYPE_U8);
il_Image *I = il_Image_new(w, h, IMTYPE_U8);
if(!I) ERRX("Can't create image %dx%d pixels", w, h);
int npix = I->height * I->width;
uint8_t *d = I->data;
for(int i = 0; i < npix; ++i, ++d){
int ampl = ilPoisson(lambda);
int ampl = il_Poisson(lambda);
*d = ampl < 255 ? ampl : 255;
}
int ret = ilwrite_png(outp, I->width, I->height, 1, I->data);
ilImage_free(&I);
int ret = il_write_png(outp, I->width, I->height, 1, I->data);
il_Image_free(&I);
if(!ret) return 1;
printf("File %s ready\n", outp);
return 0;