substitute prefix il to il_

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

View File

@ -55,7 +55,7 @@ endif()
# library # library
add_library(${PROJ} SHARED ${SOURCES}) add_library(${PROJ} SHARED ${SOURCES})
# library header files # library header files
set(LIBHEADER "usefull_macros.h") set(LIBHEADER "improclib.h")
# -I # -I
include_directories(${${PROJ}_INCLUDE_DIRS}) include_directories(${${PROJ}_INCLUDE_DIRS})
# -L # -L

View File

@ -65,7 +65,7 @@ static void morph_init(){
* @param W, H - size of binarized image (in pixels) * @param W, H - size of binarized image (in pixels)
* @return allocated memory area with converted input image * @return allocated memory area with converted input image
*/ */
uint8_t *ilfilter4(uint8_t *image, int W, int H){ uint8_t *il_filter4(uint8_t *image, int W, int H){
//FNAME(); //FNAME();
if(W < MINWIDTH || H < MINHEIGHT) return NULL; if(W < MINWIDTH || H < MINHEIGHT) return NULL;
uint8_t *ret = MALLOC(uint8_t, W*H); uint8_t *ret = MALLOC(uint8_t, W*H);
@ -96,7 +96,7 @@ uint8_t *ilfilter4(uint8_t *image, int W, int H){
* @param W, H - size of binarized image (in pixels) * @param W, H - size of binarized image (in pixels)
* @return allocated memory area with converted input image * @return allocated memory area with converted input image
*/ */
uint8_t *ilfilter8(uint8_t *image, int W, int H){ uint8_t *il_filter8(uint8_t *image, int W, int H){
//FNAME(); //FNAME();
if(W < MINWIDTH || H < MINHEIGHT) return NULL; if(W < MINWIDTH || H < MINHEIGHT) return NULL;
uint8_t *ret = MALLOC(uint8_t, W*H); uint8_t *ret = MALLOC(uint8_t, W*H);
@ -124,7 +124,7 @@ uint8_t *ilfilter8(uint8_t *image, int W, int H){
* @param W, H - size of image (pixels) * @param W, H - size of image (pixels)
* @return allocated memory area with dilation of input image * @return allocated memory area with dilation of input image
*/ */
uint8_t *ildilation(const uint8_t *image, int W, int H){ uint8_t *il_dilation(const uint8_t *image, int W, int H){
//FNAME(); //FNAME();
if(W < MINWIDTH || H < MINHEIGHT) return NULL; if(W < MINWIDTH || H < MINHEIGHT) return NULL;
int W0 = (W + 7) / 8; // width in bytes int W0 = (W + 7) / 8; // width in bytes
@ -189,7 +189,7 @@ static void mkerosion(const uint8_t *in, uint8_t *out, int W, int H){
* @param W, H - size of image (in pixels) * @param W, H - size of image (in pixels)
* @return allocated memory area with erosion of input image * @return allocated memory area with erosion of input image
*/ */
uint8_t *ilerosion(const uint8_t *image, int W, int H){ uint8_t *il_erosion(const uint8_t *image, int W, int H){
if(W < MINWIDTH || H < MINHEIGHT) return NULL; if(W < MINWIDTH || H < MINHEIGHT) return NULL;
int W0 = (W + 7) / 8; // width in bytes int W0 = (W + 7) / 8; // width in bytes
uint8_t *ret = MALLOC(uint8_t, W0*H); uint8_t *ret = MALLOC(uint8_t, W0*H);
@ -197,7 +197,7 @@ uint8_t *ilerosion(const uint8_t *image, int W, int H){
return ret; return ret;
} }
// Make erosion N times // Make erosion N times
uint8_t *ilerosionN(const uint8_t *image, int W, int H, int N){ uint8_t *il_erosionN(const uint8_t *image, int W, int H, int N){
if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL; if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL;
int W0 = (W + 7) / 8, sz = W0*H; int W0 = (W + 7) / 8, sz = W0*H;
uint8_t *in = MALLOC(uint8_t, sz), *out = MALLOC(uint8_t, sz); uint8_t *in = MALLOC(uint8_t, sz), *out = MALLOC(uint8_t, sz);
@ -211,11 +211,11 @@ uint8_t *ilerosionN(const uint8_t *image, int W, int H, int N){
return out; return out;
} }
// Make dilation N times // Make dilation N times
uint8_t *ildilationN(const uint8_t *image, int W, int H, int N){ uint8_t *il_dilationN(const uint8_t *image, int W, int H, int N){
if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL; if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL;
uint8_t *cur = (uint8_t*)image, *next = NULL; uint8_t *cur = (uint8_t*)image, *next = NULL;
for(int i = 0; i < N; ++i){ for(int i = 0; i < N; ++i){
next = ildilation(cur, W, H); next = il_dilation(cur, W, H);
if(cur != image) FREE(cur); if(cur != image) FREE(cur);
cur = next; cur = next;
} }
@ -223,30 +223,30 @@ uint8_t *ildilationN(const uint8_t *image, int W, int H, int N){
} }
// Ntimes opening // Ntimes opening
uint8_t *ilopeningN(uint8_t *image, int W, int H, int N){ uint8_t *il_openingN(uint8_t *image, int W, int H, int N){
//FNAME(); //FNAME();
if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL; if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL;
uint8_t *er = ilerosionN(image, W, H, N); uint8_t *er = il_erosionN(image, W, H, N);
uint8_t *op = ildilationN(er, W, H, N); uint8_t *op = il_dilationN(er, W, H, N);
FREE(er); FREE(er);
return op; return op;
} }
// Ntimes closing // Ntimes closing
uint8_t *ilclosingN(uint8_t *image, int W, int H, int N){ uint8_t *il_closingN(uint8_t *image, int W, int H, int N){
//FNAME(); //FNAME();
if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL; if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL;
uint8_t *di = ildilationN(image, W, H, N); uint8_t *di = il_dilationN(image, W, H, N);
uint8_t *cl = ilerosionN(di, W, H, N); uint8_t *cl = il_erosionN(di, W, H, N);
FREE(di); FREE(di);
return cl; return cl;
} }
// top hat operation: image - opening(image) // top hat operation: image - opening(image)
uint8_t *iltopHat(uint8_t *image, int W, int H, int N){ uint8_t *il_topHat(uint8_t *image, int W, int H, int N){
//FNAME(); //FNAME();
if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL; if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL;
uint8_t *op = ilopeningN(image, W, H, N); uint8_t *op = il_openingN(image, W, H, N);
int W0 = (W + 7) / 8; // width in bytes int W0 = (W + 7) / 8; // width in bytes
int wh = W0 * H; int wh = W0 * H;
OMP_FOR() OMP_FOR()
@ -256,10 +256,10 @@ uint8_t *iltopHat(uint8_t *image, int W, int H, int N){
} }
// bottom hat operation: closing(image) - image // bottom hat operation: closing(image) - image
uint8_t *ilbotHat(uint8_t *image, int W, int H, int N){ uint8_t *il_botHat(uint8_t *image, int W, int H, int N){
//FNAME(); //FNAME();
if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL; if(W < MINWIDTH || H < MINHEIGHT || N < 1) return NULL;
uint8_t *op = ilclosingN(image, W, H, N); uint8_t *op = il_closingN(image, W, H, N);
int W0 = (W + 7) / 8; // width in bytes int W0 = (W + 7) / 8; // width in bytes
int wh = W0 * H; int wh = W0 * H;
OMP_FOR() OMP_FOR()
@ -281,7 +281,7 @@ uint8_t *ilbotHat(uint8_t *image, int W, int H, int N){
* @param W, H - their size (of course, equal for both images) * @param W, H - their size (of course, equal for both images)
* @return allocated memory area with image = (im1 AND im2) * @return allocated memory area with image = (im1 AND im2)
*/ */
uint8_t *ilimand(uint8_t *im1, uint8_t *im2, int W, int H){ uint8_t *il_imand(uint8_t *im1, uint8_t *im2, int W, int H){
uint8_t *ret = MALLOC(uint8_t, W*H); uint8_t *ret = MALLOC(uint8_t, W*H);
int y; int y;
OMP_FOR() OMP_FOR()
@ -300,7 +300,7 @@ uint8_t *ilimand(uint8_t *im1, uint8_t *im2, int W, int H){
* @param W, H - their size (of course, equal for both images) * @param W, H - their size (of course, equal for both images)
* @return allocated memory area with image = (im1 AND (!im2)) * @return allocated memory area with image = (im1 AND (!im2))
*/ */
uint8_t *ilsubstim(uint8_t *im1, uint8_t *im2, int W, int H){ uint8_t *il_substim(uint8_t *im1, uint8_t *im2, int W, int H){
uint8_t *ret = MALLOC(uint8_t, W*H); uint8_t *ret = MALLOC(uint8_t, W*H);
int y; int y;
OMP_FOR() OMP_FOR()
@ -346,12 +346,12 @@ static inline void remark(size_t newval, size_t oldval, size_t *assoc){
* @param CC (o) - connected components boxes (numeration starts from 1!!!), so first box is CC->box[1], amount of boxes is CC->Nobj-1 !!! * @param CC (o) - connected components boxes (numeration starts from 1!!!), so first box is CC->box[1], amount of boxes is CC->Nobj-1 !!!
* @return an array of labeled components * @return an array of labeled components
*/ */
size_t *ilCClabel4(uint8_t *Img, int W, int H, ilConnComps **CC){ size_t *il_CClabel4(uint8_t *Img, int W, int H, il_ConnComps **CC){
size_t *assoc; size_t *assoc;
if(W < MINWIDTH || H < MINHEIGHT) return NULL; if(W < MINWIDTH || H < MINHEIGHT) return NULL;
uint8_t *f = ilfilter4(Img, W, H); // remove all non 4-connected pixels uint8_t *f = il_filter4(Img, W, H); // remove all non 4-connected pixels
//DBG("convert to size_t"); //DBG("convert to size_t");
size_t *labels = ilbin2sizet(f, W, H); size_t *labels = il_bin2sizet(f, W, H);
FREE(f); FREE(f);
//DBG("Calculate"); //DBG("Calculate");
size_t Nmax = W*H/4; // max number of 4-connected labels size_t Nmax = W*H/4; // max number of 4-connected labels
@ -414,7 +414,7 @@ size_t *ilCClabel4(uint8_t *Img, int W, int H, ilConnComps **CC){
for(size_t i = 1; i < last_assoc_idx; ++i) for(size_t i = 1; i < last_assoc_idx; ++i)
printf("%zd\t%zd\t%zd\n",i,assoc[i],indexes[i]); printf("%zd\t%zd\t%zd\n",i,assoc[i],indexes[i]);
#endif #endif
ilBox *boxes = MALLOC(ilBox, cidx); il_Box *boxes = MALLOC(il_Box, cidx);
OMP_FOR() OMP_FOR()
for(size_t i = 1; i < cidx; ++i){ // init borders for(size_t i = 1; i < cidx; ++i){ // init borders
boxes[i].xmin = W; boxes[i].xmin = W;
@ -422,7 +422,7 @@ size_t *ilCClabel4(uint8_t *Img, int W, int H, ilConnComps **CC){
} }
#pragma omp parallel shared(boxes) #pragma omp parallel shared(boxes)
{ {
ilBox *l_boxes = MALLOC(ilBox, cidx); il_Box *l_boxes = MALLOC(il_Box, cidx);
for(size_t i = 1; i < cidx; ++i){ // init borders for(size_t i = 1; i < cidx; ++i){ // init borders
l_boxes[i].xmin = W; l_boxes[i].xmin = W;
l_boxes[i].ymin = H; l_boxes[i].ymin = H;
@ -434,7 +434,7 @@ size_t *ilCClabel4(uint8_t *Img, int W, int H, ilConnComps **CC){
if(!*lptr) continue; if(!*lptr) continue;
register size_t mark = indexes[*lptr]; register size_t mark = indexes[*lptr];
*lptr = mark; *lptr = mark;
ilBox *b = &l_boxes[mark]; il_Box *b = &l_boxes[mark];
++b->area; ++b->area;
if(b->xmax < x) b->xmax = x; if(b->xmax < x) b->xmax = x;
if(b->xmin > x) b->xmin = x; if(b->xmin > x) b->xmin = x;
@ -444,7 +444,7 @@ size_t *ilCClabel4(uint8_t *Img, int W, int H, ilConnComps **CC){
} }
#pragma omp critical #pragma omp critical
for(size_t i = 1; i < cidx; ++i){ for(size_t i = 1; i < cidx; ++i){
ilBox *ob = &boxes[i], *ib = &l_boxes[i]; il_Box *ob = &boxes[i], *ib = &l_boxes[i];
if(ob->xmax < ib->xmax) ob->xmax = ib->xmax; if(ob->xmax < ib->xmax) ob->xmax = ib->xmax;
if(ob->xmin > ib->xmin) ob->xmin = ib->xmin; if(ob->xmin > ib->xmin) ob->xmin = ib->xmin;
if(ob->ymax < ib->ymax) ob->ymax = ib->ymax; if(ob->ymax < ib->ymax) ob->ymax = ib->ymax;
@ -463,7 +463,7 @@ size_t *ilCClabel4(uint8_t *Img, int W, int H, ilConnComps **CC){
}printf("\n\n"); }printf("\n\n");
#endif #endif
if(CC){ if(CC){
*CC = MALLOC(ilConnComps, 1); *CC = MALLOC(il_ConnComps, 1);
(*CC)->Nobj = cidx; (*CC)->boxes = boxes; (*CC)->Nobj = cidx; (*CC)->boxes = boxes;
}else{ }else{
FREE(boxes); FREE(boxes);

View File

@ -28,8 +28,8 @@
* @param W, H - its size (in pixels!) * @param W, H - its size (in pixels!)
* @return Image structure * @return Image structure
*/ */
ilImage *ilbin2Image(const uint8_t *image, int W, int H){ il_Image *il_bin2Image(const uint8_t *image, int W, int H){
ilImage *ret = ilImage_new(W, H, IMTYPE_U8); il_Image *ret = il_Image_new(W, H, IMTYPE_U8);
int stride = (W + 7) / 8, s1 = (stride*8 == W) ? stride : stride - 1; int stride = (W + 7) / 8, s1 = (stride*8 == W) ? stride : stride - 1;
uint8_t *data = (uint8_t*) ret->data; uint8_t *data = (uint8_t*) ret->data;
int rest = W - s1*8; int rest = W - s1*8;
@ -64,7 +64,7 @@ ilImage *ilbin2Image(const uint8_t *image, int W, int H){
* @param bk - background level (all values < bk will be 0, other will be 1) * @param bk - background level (all values < bk will be 0, other will be 1)
* @return allocated memory area with "packed" image * @return allocated memory area with "packed" image
*/ */
uint8_t *ilImage2bin(const ilImage *im, double bk){ uint8_t *il_Image2bin(const il_Image *im, double bk){
if(!im) return NULL; if(!im) return NULL;
if(im->type != IMTYPE_U8){ if(im->type != IMTYPE_U8){
WARNX("ilImage2bin(): supported only 8-bit images"); WARNX("ilImage2bin(): supported only 8-bit images");
@ -127,36 +127,36 @@ uint8_t *ilImage2bin(const ilImage *im, double bk){
} \ } \
} }
static uint8_t *Iu8(const ilImage *I, int nchannels){ static uint8_t *Iu8(const il_Image *I, int nchannels){
TRANSMACRO(uint8_t); TRANSMACRO(uint8_t);
return outp; return outp;
} }
static uint8_t *Iu16(const ilImage *I, int nchannels){ static uint8_t *Iu16(const il_Image *I, int nchannels){
TRANSMACRO(uint16_t); TRANSMACRO(uint16_t);
return outp; return outp;
} }
static uint8_t *Iu32(const ilImage *I, int nchannels){ static uint8_t *Iu32(const il_Image *I, int nchannels){
TRANSMACRO(uint32_t); TRANSMACRO(uint32_t);
return outp; return outp;
} }
static uint8_t *If(const ilImage *I, int nchannels){ static uint8_t *If(const il_Image *I, int nchannels){
TRANSMACRO(float); TRANSMACRO(float);
return outp; return outp;
} }
static uint8_t *Id(const ilImage *I, int nchannels){ static uint8_t *Id(const il_Image *I, int nchannels){
TRANSMACRO(double); TRANSMACRO(double);
return outp; return outp;
} }
/** /**
* @brief ilImage2u8 - linear transform for preparing file to save as JPEG or other type * @brief il_Image2u8 - linear transform for preparing file to save as JPEG or other type
* @param I - input image * @param I - input image
* @param nchannels - 1 or 3 colour channels * @param nchannels - 1 or 3 colour channels
* @return allocated here image for jpeg/png storing * @return allocated here image for jpeg/png storing
*/ */
uint8_t *ilImage2u8(ilImage *I, int nchannels){ // only 1 and 3 channels supported! uint8_t *il_Image2u8(il_Image *I, int nchannels){ // only 1 and 3 channels supported!
if(!I || !I->data || (nchannels != 1 && nchannels != 3)) return NULL; if(!I || !I->data || (nchannels != 1 && nchannels != 3)) return NULL;
ilImage_minmax(I); il_Image_minmax(I);
//DBG("make linear transform %dx%d, %d channels", I->width, I->height, nchannels); //DBG("make linear transform %dx%d, %d channels", I->width, I->height, nchannels);
switch(I->type){ switch(I->type){
case IMTYPE_U8: case IMTYPE_U8:
@ -204,7 +204,7 @@ Image *ST2Im(const size_t *image, int W, int H){
* @param W, H - size of image in pixels * @param W, H - size of image in pixels
* @return allocated memory area with copy of an image * @return allocated memory area with copy of an image
*/ */
size_t *ilbin2sizet(const uint8_t *image, int W, int H){ size_t *il_bin2sizet(const uint8_t *image, int W, int H){
size_t *ret = MALLOC(size_t, W * H); size_t *ret = MALLOC(size_t, W * H);
int W0 = (W + 7) / 8, s1 = W0 - 1; int W0 = (W + 7) / 8, s1 = W0 - 1;
OMP_FOR() OMP_FOR()

160
draw.c
View File

@ -32,15 +32,15 @@
// base colors: // base colors:
const uint8_t const uint8_t
ilColor_red[3] = {255, 0, 0}, il_Color_red[3] = {255, 0, 0},
ilColor_green[3] = {0, 255, 0}, il_Color_green[3] = {0, 255, 0},
ilColor_blue[3] = {0, 0, 255}, il_Color_blue[3] = {0, 0, 255},
ilColor_black[3] = {0, 0, 0}, il_Color_black[3] = {0, 0, 0},
ilColor_white[3] = {255,255,255}; il_Color_white[3] = {255,255,255};
ilImg3 *ilImg3_new(int w, int h){ il_Img3 *il_Img3_new(int w, int h){
if(w < 1 || h < 1) return NULL; if(w < 1 || h < 1) return NULL;
ilImg3 *o = MALLOC(ilImg3, 1); il_Img3 *o = MALLOC(il_Img3, 1);
if(!o) return NULL; if(!o) return NULL;
o->data = MALLOC(uint8_t, 3*w*h); o->data = MALLOC(uint8_t, 3*w*h);
if(!o->data){ if(!o->data){
@ -51,15 +51,15 @@ ilImg3 *ilImg3_new(int w, int h){
o->height = h; o->height = h;
return o; return o;
} }
void ilImg3_free(ilImg3 **I){ void il_Img3_free(il_Img3 **I){
if(!I || !*I) return; if(!I || !*I) return;
FREE((*I)->data); FREE((*I)->data);
FREE(*I); FREE(*I);
} }
ilPattern *ilPattern_new(int w, int h){ il_Pattern *il_Pattern_new(int w, int h){
if(w < 1 || h < 1) return NULL; if(w < 1 || h < 1) return NULL;
ilPattern *o = MALLOC(ilPattern, 1); il_Pattern *o = MALLOC(il_Pattern, 1);
if(!o) return NULL; if(!o) return NULL;
o->data = MALLOC(uint8_t, w*h); o->data = MALLOC(uint8_t, w*h);
if(!o->data){ if(!o->data){
@ -70,16 +70,16 @@ ilPattern *ilPattern_new(int w, int h){
o->height = h; o->height = h;
return o; return o;
} }
void ilPattern_free(ilPattern **I){ void il_Pattern_free(il_Pattern **I){
if(!I || !*I) return; if(!I || !*I) return;
FREE((*I)->data); FREE((*I)->data);
FREE(*I); FREE(*I);
} }
// make a single-channel (opaque) mask for cross; allocated here!!! // make a single-channel (opaque) mask for cross; allocated here!!!
ilPattern *ilPattern_cross(int w, int h){ il_Pattern *il_Pattern_cross(int w, int h){
int hmid = h/2, wmid = w/2; int hmid = h/2, wmid = w/2;
ilPattern *p = ilPattern_new(w, h); il_Pattern *p = il_Pattern_new(w, h);
if(!p) return NULL; if(!p) return NULL;
uint8_t *ptr = &p->data[wmid]; uint8_t *ptr = &p->data[wmid];
for(int y = 0; y < h; ++y, ptr += w) *ptr = 255; for(int y = 0; y < h; ++y, ptr += w) *ptr = 255;
@ -89,9 +89,9 @@ ilPattern *ilPattern_cross(int w, int h){
} }
// complicated cross // complicated cross
ilPattern *ilPattern_xcross(int w, int h){ il_Pattern *il_Pattern_xcross(int w, int h){
int hmid = h/2, wmid = w/2; int hmid = h/2, wmid = w/2;
ilPattern *p = ilPattern_new(w, h); il_Pattern *p = il_Pattern_new(w, h);
if(!p) return NULL; if(!p) return NULL;
uint8_t *data = p->data; uint8_t *data = p->data;
data[hmid*w + wmid] = 255; // point @ center data[hmid*w + wmid] = 255; // point @ center
@ -123,16 +123,16 @@ for(int y = 0; y < h; ++y){ \
} }
/** /**
* @brief ilPattern_star - create pseudo-star Moffat pattern with max ampl. 255 and given FWHM * @brief il_Pattern_star - create pseudo-star Moffat pattern with max ampl. 255 and given FWHM
* @param w - width * @param w - width
* @param h - height * @param h - height
* @param fwhm - FWHM * @param fwhm - FWHM
* @param beta - `beta` parameter of Moffat * @param beta - `beta` parameter of Moffat
* @return pattern or NULL if error * @return pattern or NULL if error
*/ */
ilPattern *ilPattern_star(int w, int h, double fwhm, double beta){ il_Pattern *il_Pattern_star(int w, int h, double fwhm, double beta){
if(fwhm < 1.) return NULL; if(fwhm < 1.) return NULL;
ilPattern *p = ilPattern_new(w, h); il_Pattern *p = il_Pattern_new(w, h);
if(!p) return NULL; if(!p) return NULL;
int w2 = w/2, h2 = h/2; // center of image int w2 = w/2, h2 = h/2; // center of image
double hwhm = fwhm / 2., theta2 = hwhm*hwhm; double hwhm = fwhm / 2., theta2 = hwhm*hwhm;
@ -141,7 +141,7 @@ ilPattern *ilPattern_star(int w, int h, double fwhm, double beta){
} }
/** /**
* @brief ilImage_star - generate subimage with 'star'; max amplitude for float and double == 1. * @brief il_Image_star - generate subimage with 'star'; max amplitude for float and double == 1.
* @param type - image type * @param type - image type
* @param w - image width * @param w - image width
* @param h - height * @param h - height
@ -149,9 +149,9 @@ ilPattern *ilPattern_star(int w, int h, double fwhm, double beta){
* @param beta - beta parameter * @param beta - beta parameter
* @return * @return
*/ */
ilImage *ilImage_star(ilimtype_t type, int w, int h, double fwhm, double beta){ il_Image *il_Image_star(il_imtype_t type, int w, int h, double fwhm, double beta){
if(fwhm < 1.) return NULL; if(fwhm < 1.) return NULL;
ilImage *p = ilImage_new(w, h, type); il_Image *p = il_Image_new(w, h, type);
if(!p) return NULL; if(!p) return NULL;
int w2 = w/2, h2 = h/2; int w2 = w/2, h2 = h/2;
double hwhm = fwhm / 2., theta2 = hwhm*hwhm; double hwhm = fwhm / 2., theta2 = hwhm*hwhm;
@ -179,13 +179,13 @@ ilImage *ilImage_star(ilimtype_t type, int w, int h, double fwhm, double beta){
#undef DRAW_star #undef DRAW_star
/** /**
* @brief ilPattern_draw3 - draw pattern @ 3-channel image * @brief il_Img3_drawpattern - draw pattern @ 3-channel image
* @param img (io) - image * @param img (io) - image
* @param p (i) - the pattern * @param p (i) - the pattern
* @param xc, yc - coordinates of pattern center @ image * @param xc, yc - coordinates of pattern center @ image
* @param color - color to draw pattern (when opaque == 255) * @param color - color to draw pattern (when opaque == 255)
*/ */
void ilImg3_drawpattern(ilImg3 *img, const ilPattern *p, int xc, int yc, const uint8_t color[3]){ void il_Img3_drawpattern(il_Img3 *img, const il_Pattern *p, int xc, int yc, const uint8_t color[3]){
if(!img || !p) return; if(!img || !p) return;
int xul = xc - p->width/2, yul = yc - p->height/2; int xul = xc - p->width/2, yul = yc - p->height/2;
int xdr = xul+p->width-1, ydr = yul+p->height-1; int xdr = xul+p->width-1, ydr = yul+p->height-1;
@ -240,13 +240,13 @@ void ilImg3_drawpattern(ilImg3 *img, const ilPattern *p, int xc, int yc, const u
} }
/** /**
* @brief iladd_subimage - draw subimage over given image (by sum) * @brief il_Image_addsub - draw subimage over given image (by sum)
* @param img (io) - image * @param img (io) - image
* @param p (i) - subimage * @param p (i) - subimage
* @param xc, yc - coordinates of pattern center @ image * @param xc, yc - coordinates of pattern center @ image
* @param weight - img = img + p*weight * @param weight - img = img + p*weight
*/ */
void ilImage_addsub(ilImage *img, const ilImage *p, int xc, int yc, double weight){ void il_Image_addsub(il_Image *img, const il_Image *p, int xc, int yc, double weight){
if(!img || !p) return; if(!img || !p) return;
if(img->type != p->type){ if(img->type != p->type){
WARNX("iladd_subimage(): types of image and subimage must match"); WARNX("iladd_subimage(): types of image and subimage must match");
@ -303,13 +303,13 @@ void ilImage_addsub(ilImage *img, const ilImage *p, int xc, int yc, double weigh
#define PUTP(type) do{((type*)I->data)[I->width*y+x] = *((type*)val);}while(0) #define PUTP(type) do{((type*)I->data)[I->width*y+x] = *((type*)val);}while(0)
/** /**
* @brief ilImage_drawpix - put pixel @(x,y) * @brief il_Image_drawpix - put pixel @(x,y)
* @param I - image * @param I - image
* @param x - point coordinates * @param x - point coordinates
* @param y * @param y
* @param val - data value to set (the same type as I->data) * @param val - data value to set (the same type as I->data)
*/ */
void ilImage_drawpix(ilImage *I, int x, int y, const void *val){ void il_Image_drawpix(il_Image *I, int x, int y, const void *val){
if(x < 0 || x >= I->width || y < 0 || y >= I->height) return; if(x < 0 || x >= I->width || y < 0 || y >= I->height) return;
switch(I->type){ switch(I->type){
case IMTYPE_U8: case IMTYPE_U8:
@ -333,12 +333,13 @@ void ilImage_drawpix(ilImage *I, int x, int y, const void *val){
} }
#undef PUTP #undef PUTP
static void plotLineLow(ilImage *I, int x0, int y0, int x1, int y1, const void *val){ // plot line across X axe
static void plotLineLow(il_Image *I, int x0, int y0, int x1, int y1, const void *val){
int dx = x1 - x0, dy = y1 - y0, yi = 1; int dx = x1 - x0, dy = y1 - y0, yi = 1;
if(dy < 0){ yi = -1; dy = -dy; } if(dy < 0){ yi = -1; dy = -dy; }
int D = (2 * dy) - dx, y = y0; int D = (2 * dy) - dx, y = y0;
for(int x = x0; x <= x1; ++x){ for(int x = x0; x <= x1; ++x){
ilImage_drawpix(I, x, y, val); il_Image_drawpix(I, x, y, val);
if(D > 0){ if(D > 0){
y += yi; y += yi;
D += 2 * (dy - dx); D += 2 * (dy - dx);
@ -347,12 +348,13 @@ static void plotLineLow(ilImage *I, int x0, int y0, int x1, int y1, const void *
} }
} }
} }
static void plotLineHigh(ilImage *I, int x0, int y0, int x1, int y1, const void *val){ // plot line across Y axe
static void plotLineHigh(il_Image *I, int x0, int y0, int x1, int y1, const void *val){
int dx = x1 - x0, dy = y1 - y0, xi = 1; int dx = x1 - x0, dy = y1 - y0, xi = 1;
if(dx < 0){ xi = -1; dx = -dx; } if(dx < 0){ xi = -1; dx = -dx; }
int D = (2 * dx) - dy, x = x0; int D = (2 * dx) - dy, x = x0;
for(int y = y0; y <= y1; ++y){ for(int y = y0; y <= y1; ++y){
ilImage_drawpix(I, x, y, val); il_Image_drawpix(I, x, y, val);
if(D > 0){ if(D > 0){
x += xi; x += xi;
D += 2 * (dx - dy); D += 2 * (dx - dy);
@ -362,7 +364,7 @@ static void plotLineHigh(ilImage *I, int x0, int y0, int x1, int y1, const void
} }
} }
/** /**
* @brief ilImage_drawline - Bresenham's line drawing on Image * @brief il_Image_drawline - Bresenham's line drawing on Image
* @param I - image * @param I - image
* @param x0 - first point * @param x0 - first point
* @param y0 * @param y0
@ -370,7 +372,7 @@ static void plotLineHigh(ilImage *I, int x0, int y0, int x1, int y1, const void
* @param y1 * @param y1
* @param val - value to put * @param val - value to put
*/ */
void ilImage_drawline(ilImage *I, int x0, int y0, int x1, int y1, const void *val){ void il_Image_drawline(il_Image *I, int x0, int y0, int x1, int y1, const void *val){
if(!I || !I->data) return; if(!I || !I->data) return;
if(ABS(y1 - y0) < ABS(x1 - x0)){ if(ABS(y1 - y0) < ABS(x1 - x0)){
if(x0 > x1) plotLineLow(I, x1, y1, x0, y0, val); if(x0 > x1) plotLineLow(I, x1, y1, x0, y0, val);
@ -382,26 +384,26 @@ void ilImage_drawline(ilImage *I, int x0, int y0, int x1, int y1, const void *va
} }
/** /**
* @brief ilImage_drawcircle - Bresenham's circle drawing on Image * @brief il_Image_drawcircle - Bresenham's circle drawing on Image
* @param I - image * @param I - image
* @param x0- circle center * @param x0- circle center
* @param y0 * @param y0
* @param R - circle radius * @param R - circle radius
* @param val - value to put * @param val - value to put
*/ */
void ilImage_drawcircle(ilImage *I, int x0, int y0, int R, const void *val){ void il_Image_drawcircle(il_Image *I, int x0, int y0, int R, const void *val){
int x = R; int x = R;
int y = 0; int y = 0;
int radiusError = 1-x; int radiusError = 1-x;
while(x >= y){ while(x >= y){
ilImage_drawpix(I, x + x0, y + y0, val); il_Image_drawpix(I, x + x0, y + y0, val);
ilImage_drawpix(I, y + x0, x + y0, val); il_Image_drawpix(I, y + x0, x + y0, val);
ilImage_drawpix(I, -x + x0, y + y0, val); il_Image_drawpix(I, -x + x0, y + y0, val);
ilImage_drawpix(I, -y + x0, x + y0, val); il_Image_drawpix(I, -y + x0, x + y0, val);
ilImage_drawpix(I, -x + x0, -y + y0, val); il_Image_drawpix(I, -x + x0, -y + y0, val);
ilImage_drawpix(I, -y + x0, -x + y0, val); il_Image_drawpix(I, -y + x0, -x + y0, val);
ilImage_drawpix(I, x + x0, -y + y0, val); il_Image_drawpix(I, x + x0, -y + y0, val);
ilImage_drawpix(I, y + x0, -x + y0, val); il_Image_drawpix(I, y + x0, -x + y0, val);
y++; y++;
if (radiusError < 0){ if (radiusError < 0){
radiusError += 2 * y + 1; radiusError += 2 * y + 1;
@ -414,11 +416,11 @@ void ilImage_drawcircle(ilImage *I, int x0, int y0, int R, const void *val){
} }
/** /**
* @brief ilImg3_setcolor - set image pixel to given color or its negative (if original color is near to target) * @brief il_Img3_setcolor - set image pixel to given color or its negative (if original color is near to target)
* @param impixel - pixel to change * @param impixel - pixel to change
* @param color - desired color * @param color - desired color
*/ */
void ilImg3_setcolor(uint8_t impixel[3], const uint8_t color[3]){ void il_Img3_setcolor(uint8_t impixel[3], const uint8_t color[3]){
int invert = 0; int invert = 0;
for(int i = 0; i < 3; ++i) for(int i = 0; i < 3; ++i)
if(impixel[i] > color[i]){ if(impixel[i] > color[i]){
@ -429,25 +431,26 @@ void ilImg3_setcolor(uint8_t impixel[3], const uint8_t color[3]){
} }
/** /**
* @brief ilImg3_drawpix - draw pixel with `color` or its negative on coloured image * @brief il_Img3_drawpix - draw pixel with `color` or its negative on coloured image
* @param I - image * @param I - image
* @param x - point coordinates * @param x - point coordinates
* @param y * @param y
* @param color - desired color * @param color - desired color
*/ */
void ilImg3_drawpix(ilImg3 *I, int x, int y, const uint8_t color[3]){ void il_Img3_drawpix(il_Img3 *I, int x, int y, const uint8_t color[3]){
if(!I || !I->data) return; if(!I || !I->data) return;
if(x < 0 || x >= I->width) return; if(x < 0 || x >= I->width) return;
if(y < 0 || y >= I->height) return; if(y < 0 || y >= I->height) return;
ilImg3_setcolor(I->data + 3*(I->width*y+x), color); il_Img3_setcolor(I->data + 3*(I->width*y+x), color);
} }
static void plotLineLow3(ilImg3 *I, int x0, int y0, int x1, int y1, const uint8_t color[3]){ // draw lines across X or Y axis over color image
static void plotLineLow3(il_Img3 *I, int x0, int y0, int x1, int y1, const uint8_t color[3]){
int dx = x1 - x0, dy = y1 - y0, yi = 1; int dx = x1 - x0, dy = y1 - y0, yi = 1;
if(dy < 0){ yi = -1; dy = -dy; } if(dy < 0){ yi = -1; dy = -dy; }
int D = (2 * dy) - dx, y = y0; int D = (2 * dy) - dx, y = y0;
for(int x = x0; x <= x1; ++x){ for(int x = x0; x <= x1; ++x){
ilImg3_drawpix(I, x, y, color); il_Img3_drawpix(I, x, y, color);
if(D > 0){ if(D > 0){
y += yi; y += yi;
D += 2 * (dy - dx); D += 2 * (dy - dx);
@ -456,13 +459,12 @@ static void plotLineLow3(ilImg3 *I, int x0, int y0, int x1, int y1, const uint8_
} }
} }
} }
static void plotLineHigh3(il_Img3 *I, int x0, int y0, int x1, int y1, const uint8_t color[3]){
static void plotLineHigh3(ilImg3 *I, int x0, int y0, int x1, int y1, const uint8_t color[3]){
int dx = x1 - x0, dy = y1 - y0, xi = 1; int dx = x1 - x0, dy = y1 - y0, xi = 1;
if(dx < 0){ xi = -1; dx = -dx; } if(dx < 0){ xi = -1; dx = -dx; }
int D = (2 * dx) - dy, x = x0; int D = (2 * dx) - dy, x = x0;
for(int y = y0; y <= y1; ++y){ for(int y = y0; y <= y1; ++y){
ilImg3_drawpix(I, x, y, color); il_Img3_drawpix(I, x, y, color);
if(D > 0){ if(D > 0){
x += xi; x += xi;
D += 2 * (dx - dy); D += 2 * (dx - dy);
@ -473,7 +475,7 @@ static void plotLineHigh3(ilImg3 *I, int x0, int y0, int x1, int y1, const uint8
} }
/** /**
* @brief ilImg3_drawline - Bresenham's line drawing on Img3 * @brief il_Img3_drawline - Bresenham's line drawing on Img3
* @param I - image * @param I - image
* @param x0 - first point * @param x0 - first point
* @param y0 * @param y0
@ -481,7 +483,7 @@ static void plotLineHigh3(ilImg3 *I, int x0, int y0, int x1, int y1, const uint8
* @param y1 * @param y1
* @param color - drawing color * @param color - drawing color
*/ */
void ilImg3_drawline(ilImg3 *I, int x0, int y0, int x1, int y1, const uint8_t color[3]){ void il_Img3_drawline(il_Img3 *I, int x0, int y0, int x1, int y1, const uint8_t color[3]){
if(!I || !I->data) return; if(!I || !I->data) return;
if(ABS(y1 - y0) < ABS(x1 - x0)){ if(ABS(y1 - y0) < ABS(x1 - x0)){
if(x0 > x1) plotLineLow3(I, x1, y1, x0, y0, color); if(x0 > x1) plotLineLow3(I, x1, y1, x0, y0, color);
@ -493,26 +495,26 @@ void ilImg3_drawline(ilImg3 *I, int x0, int y0, int x1, int y1, const uint8_t co
} }
/** /**
* @brief ilImg3_drawcircle - Bresenham's circle drawing on Image * @brief il_Img3_drawcircle - Bresenham's circle drawing on Image
* @param I - image * @param I - image
* @param x0- circle center * @param x0- circle center
* @param y0 * @param y0
* @param R - circle radius * @param R - circle radius
* @param val - value to put * @param val - value to put
*/ */
void ilImg3_drawcircle(ilImg3 *I, int x0, int y0, int R, const uint8_t color[3]){ void il_Img3_drawcircle(il_Img3 *I, int x0, int y0, int R, const uint8_t color[3]){
int x = R; int x = R;
int y = 0; int y = 0;
int radiusError = 1-x; int radiusError = 1-x;
while(x >= y){ while(x >= y){
ilImg3_drawpix(I, x + x0, y + y0, color); il_Img3_drawpix(I, x + x0, y + y0, color);
ilImg3_drawpix(I, y + x0, x + y0, color); il_Img3_drawpix(I, y + x0, x + y0, color);
ilImg3_drawpix(I, -x + x0, y + y0, color); il_Img3_drawpix(I, -x + x0, y + y0, color);
ilImg3_drawpix(I, -y + x0, x + y0, color); il_Img3_drawpix(I, -y + x0, x + y0, color);
ilImg3_drawpix(I, -x + x0, -y + y0, color); il_Img3_drawpix(I, -x + x0, -y + y0, color);
ilImg3_drawpix(I, -y + x0, -x + y0, color); il_Img3_drawpix(I, -y + x0, -x + y0, color);
ilImg3_drawpix(I, x + x0, -y + y0, color); il_Img3_drawpix(I, x + x0, -y + y0, color);
ilImg3_drawpix(I, y + x0, -x + y0, color); il_Img3_drawpix(I, y + x0, -x + y0, color);
y++; y++;
if (radiusError < 0){ if (radiusError < 0){
radiusError += 2 * y + 1; radiusError += 2 * y + 1;
@ -527,26 +529,26 @@ void ilImg3_drawcircle(ilImg3 *I, int x0, int y0, int R, const uint8_t color[3])
// dots period in dotted line // dots period in dotted line
#define DOTSTEP (7) #define DOTSTEP (7)
static void drawhline(ilImg3 *img, int y, const uint8_t color[3], int dots){ static void drawhline(il_Img3 *img, int y, const uint8_t color[3], int dots){
if(y < 0 || y >= img->height) return; if(y < 0 || y >= img->height) return;
uint8_t *data = img->data + 3*y*img->width; uint8_t *data = img->data + 3*y*img->width;
for(int x = 0; x < img->width; ++x, data += 3){ for(int x = 0; x < img->width; ++x, data += 3){
if(dots && (x % DOTSTEP)) continue; if(dots && (x % DOTSTEP)) continue;
ilImg3_setcolor(data, color); il_Img3_setcolor(data, color);
} }
} }
static void drawvline(ilImg3 *img, int x, const uint8_t color[3], int dots){ static void drawvline(il_Img3 *img, int x, const uint8_t color[3], int dots){
if(x < 0 || x >= img->width) return; if(x < 0 || x >= img->width) return;
uint8_t *data = img->data + 3*x; uint8_t *data = img->data + 3*x;
int step = 3*img->width; int step = 3*img->width;
for(int y = 0; y < img->height; ++y, data += step){ for(int y = 0; y < img->height; ++y, data += step){
if(dots && (y % DOTSTEP)) continue; if(dots && (y % DOTSTEP)) continue;
ilImg3_setcolor(data, color); il_Img3_setcolor(data, color);
} }
} }
/** /**
* @brief ilImg3_drawgrid - draw simplest grid on image * @brief il_Img3_drawgrid - draw simplest grid on image
* @param img - image * @param img - image
* @param x0 - grid center (0,0) * @param x0 - grid center (0,0)
* @param y0 * @param y0
@ -554,7 +556,7 @@ static void drawvline(ilImg3 *img, int x, const uint8_t color[3], int dots){
* @param ystep - step of horizontal lines (-//-) * @param ystep - step of horizontal lines (-//-)
* @param color - color to draw * @param color - color to draw
*/ */
void ilImg3_drawgrid(ilImg3 *img, int x0, int y0, int xstep, int ystep, const uint8_t color[3]){ void il_Img3_drawgrid(il_Img3 *img, int x0, int y0, int xstep, int ystep, const uint8_t color[3]){
int dotted = 0; int dotted = 0;
if(ystep){ if(ystep){
if(ystep < 0){ dotted = 1; ystep = -ystep; } if(ystep < 0){ dotted = 1; ystep = -ystep; }
@ -565,7 +567,7 @@ void ilImg3_drawgrid(ilImg3 *img, int x0, int y0, int xstep, int ystep, const ui
/*if(!dotted){ /*if(!dotted){
char s[32]; char s[32];
snprintf(s, 31, "%d", (y-y0)/ ystep); snprintf(s, 31, "%d", (y-y0)/ ystep);
ilImg3_putstring(img, s, img->width/2+2, y-2, color); il_Img3_putstring(img, s, img->width/2+2, y-2, color);
}*/ }*/
} }
} }
@ -578,14 +580,14 @@ void ilImg3_drawgrid(ilImg3 *img, int x0, int y0, int xstep, int ystep, const ui
/*if(!dotted){ /*if(!dotted){
char s[32]; char s[32];
snprintf(s, 31, "%d", (x-x0)/ xstep); snprintf(s, 31, "%d", (x-x0)/ xstep);
ilImg3_putstring(img, s, x+2, img->height/2-2, color); il_Img3_putstring(img, s, x+2, img->height/2-2, color);
}*/ }*/
} }
} }
} }
/** /**
* @brief ilImg3_subimage - allocate image with size (x1-x0+1)x(y1-y0+1) and copy into it subimage of I * @brief il_Img3_subimage - allocate image with size (x1-x0+1)x(y1-y0+1) and copy into it subimage of I
* @param I - original * @param I - original
* @param x0 - left upper point * @param x0 - left upper point
* @param y0 * @param y0
@ -593,18 +595,18 @@ void ilImg3_drawgrid(ilImg3 *img, int x0, int y0, int xstep, int ystep, const ui
* @param y1 * @param y1
* @return image allocated here (or NULL if error) * @return image allocated here (or NULL if error)
*/ */
ilImg3 *ilImg3_subimage(const ilImg3 *I, int x0, int y0, int x1, int y1){ il_Img3 *il_Img3_subimage(const il_Img3 *I, int x0, int y0, int x1, int y1){
if(x0 >= x1 || x1 < 0 || y0 >= y1 || y1 < 0 || !I || !I->data || !I->height || !I->width) return NULL; if(x0 >= x1 || x1 < 0 || y0 >= y1 || y1 < 0 || !I || !I->data || !I->height || !I->width) return NULL;
ilImg3 *O = ilImg3_new(x1-x0+1, y1-y0+1); il_Img3 *O = il_Img3_new(x1-x0+1, y1-y0+1);
if(!O) return NULL; if(!O) return NULL;
// input coordinates of angles to copy & len for memcpy // input coordinates of angles to copy & len for memcpy
int ixl = x0 > 0 ? x0 : 0, ixr = x1 < I->width ? x1 : I->width-1, xlen = 3*(ixr-ixl+1); int ixl = x0 > 0 ? x0 : 0, ixr = x1 < I->width ? x1 : I->width-1, xlen = 3*(ixr-ixl+1);
int iyt = y0 > 0 ? y0 : 0, iyb = y1 < I->height ? y1 : I->height-1, ypix = iyb - iyt + 1; int iyt = y0 > 0 ? y0 : 0, iyb = y1 < I->height ? y1 : I->height-1, ypix = iyb - iyt + 1;
// output coordinates // output coordinates
int oxl = x0 < 0 ? -x0 : 0, oxr = oxl + ixr - ixl; int oxl = x0 < 0 ? -x0 : 0;
int oyt = y0 < 0 ? -y0 : 0, oyb = oyt + iyb - iyt; int oyt = y0 < 0 ? -y0 : 0;
DBG("input subimage: from (%d, %d) to (%d, %d), w=%d, h=%d", ixl,iyt, ixr, iyb, xlen/3, ypix); DBG("input subimage: from (%d, %d) to (%d, %d), w=%d, h=%d", ixl,iyt, ixr, iyb, xlen/3, ypix);
DBG("output subimage: from (%d, %d) to (%d, %d)", oxl,oyt, oxr, oyb); DBG("output subimage: from (%d, %d) to (%d, %d)", oxl,oyt, oxl + ixr - ixl, oyt + iyb - iyt);
OMP_FOR() OMP_FOR()
for(int y = 0; y < ypix; ++y){ for(int y = 0; y < ypix; ++y){
uint8_t *in = I->data + (ixl + (iyt + y)*I->width)*3; uint8_t *in = I->data + (ixl + (iyt + y)*I->width)*3;

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

View File

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

View File

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

View File

@ -43,47 +43,47 @@ int main(int argc, char **argv){
parseargs(&argc, &argv, cmdlnopts); parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts); if(help) showhelp(-1, cmdlnopts);
if(!infile) ERRX("Point name of input file"); 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(!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); uint8_t ibg = (int)(bg + 0.5);
printf("Background level: %d\n", ibg); printf("Background level: %d\n", ibg);
int w = I->width, h = I->height, wh = w*h; 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); memcpy(Ibg->data, I->data, wh);
uint8_t *idata = (uint8_t*) Ibg->data; uint8_t *idata = (uint8_t*) Ibg->data;
for(int i = 0; i < wh; ++i) idata[i] = (idata[i] > ibg) ? idata[i] - ibg : 0; 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(); double t0 = dtime();
uint8_t *Ibin = ilImage2bin(I, bg); uint8_t *Ibin = il_Image2bin(I, bg);
if(!Ibin) ERRX("Can't binarize image"); if(!Ibin) ERRX("Can't binarize image");
green("Binarization: %gms\n", 1e3*(dtime()-t0)); green("Binarization: %gms\n", 1e3*(dtime()-t0));
if(neros > 0){ if(neros > 0){
t0 = dtime(); t0 = dtime();
uint8_t *eros = ilerosionN(Ibin, w, h, neros); uint8_t *eros = il_erosionN(Ibin, w, h, neros);
FREE(Ibin); FREE(Ibin);
Ibin = eros; Ibin = eros;
green("%d erosions: %gms\n", neros, 1e3*(dtime()-t0)); green("%d erosions: %gms\n", neros, 1e3*(dtime()-t0));
} }
if(ndilat > 0){ if(ndilat > 0){
t0 = dtime(); t0 = dtime();
uint8_t *dilat = ildilationN(Ibin, w, h, ndilat); uint8_t *dilat = il_dilationN(Ibin, w, h, ndilat);
FREE(Ibin); FREE(Ibin);
Ibin = dilat; Ibin = dilat;
green("%d dilations: %gms\n", ndilat, 1e3*(dtime()-t0)); green("%d dilations: %gms\n", ndilat, 1e3*(dtime()-t0));
} }
if(outbin){ if(outbin){
ilImage *tmp = ilbin2Image(Ibin, w, h); il_Image *tmp = il_bin2Image(Ibin, w, h);
ilwrite_jpg(outbin, tmp->width, tmp->height, 1, (uint8_t*)tmp->data, 95); il_write_jpg(outbin, tmp->width, tmp->height, 1, (uint8_t*)tmp->data, 95);
ilImage_free(&tmp); il_Image_free(&tmp);
} }
ilConnComps *comps; il_ConnComps *comps;
t0 = dtime(); 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)); green("Labeling: %gms\n", 1e3*(dtime()-t0));
if(labels && comps->Nobj > 1){ if(labels && comps->Nobj > 1){
printf("Detected %zd components\n", 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){ 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); 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(help) showhelp(-1, cmdlnopts);
if(w < 1 || h < 1) ERRX("Wrong image size"); if(w < 1 || h < 1) ERRX("Wrong image size");
if(lambda < 1.) ERRX("LAMBDA should be >=1"); 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); if(!I) ERRX("Can't create image %dx%d pixels", w, h);
int npix = I->height * I->width; int npix = I->height * I->width;
uint8_t *d = I->data; uint8_t *d = I->data;
for(int i = 0; i < npix; ++i, ++d){ for(int i = 0; i < npix; ++i, ++d){
int ampl = ilPoisson(lambda); int ampl = il_Poisson(lambda);
*d = ampl < 255 ? ampl : 255; *d = ampl < 255 ? ampl : 255;
} }
int ret = ilwrite_png(outp, I->width, I->height, 1, I->data); int ret = il_write_png(outp, I->width, I->height, 1, I->data);
ilImage_free(&I); il_Image_free(&I);
if(!ret) return 1; if(!ret) return 1;
printf("File %s ready\n", outp); printf("File %s ready\n", outp);
return 0; return 0;

View File

@ -32,7 +32,7 @@
typedef struct{ typedef struct{
const char signature[8]; const char signature[8];
uint8_t len; uint8_t len;
ilInputType it; il_InputType it;
} imsign; } imsign;
const imsign signatures[] = { const imsign signatures[] = {
@ -70,7 +70,7 @@ const int bytes[IMTYPE_AMOUNT] = {
}; };
// return amount of bytes per pixel for given image type // return amount of bytes per pixel for given image type
int ilgetpixbytes(ilimtype_t type){ int il_getpixbytes(il_imtype_t type){
if(type >= IMTYPE_AMOUNT) return -1; if(type >= IMTYPE_AMOUNT) return -1;
return bytes[type]; return bytes[type];
} }
@ -80,7 +80,7 @@ int ilgetpixbytes(ilimtype_t type){
* @param f - opened image file structure * @param f - opened image file structure
* @return image type or T_WRONG * @return image type or T_WRONG
*/ */
static ilInputType imtype(FILE *f){ static il_InputType imtype(FILE *f){
char signature[8]; char signature[8];
int x = fread(signature, 1, 7, f); int x = fread(signature, 1, 7, f);
DBG("x=%d", x); DBG("x=%d", x);
@ -103,11 +103,11 @@ static ilInputType imtype(FILE *f){
} }
/** /**
* @brief ilchkinput - check file/directory name * @brief il_chkinput - check file/directory name
* @param name - name of file or directory * @param name - name of file or directory
* @return type of `name` * @return type of `name`
*/ */
ilInputType ilchkinput(const char *name){ il_InputType il_chkinput(const char *name){
DBG("input name: %s", name); DBG("input name: %s", name);
struct stat fd_stat; struct stat fd_stat;
if(stat(name, &fd_stat)){ if(stat(name, &fd_stat)){
@ -129,25 +129,25 @@ ilInputType ilchkinput(const char *name){
WARN("Can't open file %s", name); WARN("Can't open file %s", name);
return T_WRONG; return T_WRONG;
} }
ilInputType tp = imtype(f); il_InputType tp = imtype(f);
DBG("Image type of %s is %d", name, tp); DBG("Image type of %s is %d", name, tp);
fclose(f); fclose(f);
return tp; return tp;
} }
/** /**
* @brief ilu8toImage - convert uint8_t data to Image structure * @brief il_u8toImage - convert uint8_t data to Image structure
* @param data - original image data * @param data - original image data
* @param width - image width * @param width - image width
* @param height - image height * @param height - image height
* @param stride - image width with alignment * @param stride - image width with alignment
* @return Image structure (fully allocated, you can FREE(data) after it) * @return Image structure (fully allocated, you can FREE(data) after it)
*/ */
ilImage *ilu82Image(const uint8_t *data, int width, int height){ il_Image *il_u82Image(const uint8_t *data, int width, int height){
FNAME(); FNAME();
ilImage *outp = ilImage_new(width, height, IMTYPE_U8); il_Image *outp = il_Image_new(width, height, IMTYPE_U8);
memcpy(outp->data, data, width*height); memcpy(outp->data, data, width*height);
ilImage_minmax(outp); il_Image_minmax(outp);
return outp; return outp;
} }
@ -156,50 +156,50 @@ ilImage *ilu82Image(const uint8_t *data, int width, int height){
* @param name - filename * @param name - filename
* @return Image structure or NULL * @return Image structure or NULL
*/ */
static inline ilImage *im_loadmono(const char *name){ static inline il_Image *im_loadmono(const char *name){
int width, height, channels; int width, height, channels;
uint8_t *img = stbi_load(name, &width, &height, &channels, 1); uint8_t *img = stbi_load(name, &width, &height, &channels, 1);
if(!img){ if(!img){
WARNX("Error in loading the image %s\n", name); WARNX("Error in loading the image %s\n", name);
return NULL; return NULL;
} }
ilImage *I = MALLOC(ilImage, 1); il_Image *I = MALLOC(il_Image, 1);
I->data = img; I->data = img;
I->width = width; I->width = width;
I->height = height; I->height = height;
I->type = IMTYPE_U8; I->type = IMTYPE_U8;
I->pixbytes = 1; I->pixbytes = 1;
ilImage_minmax(I); il_Image_minmax(I);
return I; return I;
} }
/** /**
* @brief ilImage_read - read image from any supported file type * @brief il_Image_read - read image from any supported file type
* @param name - path to image * @param name - path to image
* @return image or NULL if failed * @return image or NULL if failed
*/ */
ilImage *ilImage_read(const char *name){ il_Image *il_Image_read(const char *name){
ilInputType tp = ilchkinput(name); il_InputType tp = il_chkinput(name);
if(tp == T_DIRECTORY || tp == T_WRONG){ if(tp == T_DIRECTORY || tp == T_WRONG){
WARNX("Bad file type to read"); WARNX("Bad file type to read");
return NULL; return NULL;
} }
ilImage *outp = im_loadmono(name); il_Image *outp = im_loadmono(name);
return outp; return outp;
} }
/** /**
* @brief ilImg3_read - read color image from file 'name' * @brief il_Img3_read - read color image from file 'name'
* @param name - input file name * @param name - input file name
* @return image read or NULL if error * @return image read or NULL if error
*/ */
ilImg3 *ilImg3_read(const char *name){ il_Img3 *il_Img3_read(const char *name){
ilInputType tp = ilchkinput(name); il_InputType tp = il_chkinput(name);
if(tp == T_DIRECTORY || tp == T_WRONG){ if(tp == T_DIRECTORY || tp == T_WRONG){
WARNX("Bad file type to read"); WARNX("Bad file type to read");
return NULL; return NULL;
} }
ilImg3 *I = MALLOC(ilImg3, 1); il_Img3 *I = MALLOC(il_Img3, 1);
int channels; int channels;
I->data = stbi_load(name, &I->width, &I->height, &channels, 3); I->data = stbi_load(name, &I->width, &I->height, &channels, 3);
if(!I->data){ if(!I->data){
@ -210,36 +210,36 @@ ilImg3 *ilImg3_read(const char *name){
} }
/** /**
* @brief ilImage_new - allocate memory for new struct Image & Image->data * @brief il_Image_new - allocate memory for new struct Image & Image->data
* @param w, h - image size * @param w, h - image size
* @return data allocated here * @return data allocated here
*/ */
ilImage *ilImage_new(int w, int h, ilimtype_t type){ il_Image *il_Image_new(int w, int h, il_imtype_t type){
if(w < 1 || h < 1) return NULL; if(w < 1 || h < 1) return NULL;
if(type >= IMTYPE_AMOUNT) return NULL; if(type >= IMTYPE_AMOUNT) return NULL;
ilImage *o = MALLOC(ilImage, 1); il_Image *o = MALLOC(il_Image, 1);
o->width = w; o->width = w;
o->height = h; o->height = h;
o->type = type; o->type = type;
o->pixbytes = ilgetpixbytes(type); o->pixbytes = il_getpixbytes(type);
o->data = calloc(w*h, o->pixbytes); o->data = calloc(w*h, o->pixbytes);
if(!o->data) ERR("calloc()"); if(!o->data) ERR("calloc()");
return o; return o;
} }
/** /**
* @brief ilImage_sim - allocate memory for new empty Image with similar size & data type * @brief il_Image_sim - allocate memory for new empty Image with similar size & data type
* @param i - sample image * @param i - sample image
* @return data allocated here (with empty keylist & zeros in data) * @return data allocated here (with empty keylist & zeros in data)
*/ */
ilImage *ilImage_sim(const ilImage *i){ il_Image *il_Image_sim(const il_Image *i){
if(!i) return NULL; if(!i) return NULL;
ilImage *outp = ilImage_new(i->width, i->height, i->type); il_Image *outp = il_Image_new(i->width, i->height, i->type);
return outp; return outp;
} }
// free image data // free image data
void ilImage_free(ilImage **img){ void il_Image_free(il_Image **img){
if(!img || !*img) return; if(!img || !*img) return;
FREE((*img)->data); FREE((*img)->data);
FREE(*img); FREE(*img);
@ -247,11 +247,11 @@ void ilImage_free(ilImage **img){
/** /**
* @brief ilhistogram8 - calculate image histogram for 8-bit image * @brief il_histogram8 - calculate image histogram for 8-bit image
* @param I - orig * @param I - orig
* @return 256 byte array * @return 256 byte array
*/ */
size_t *ilhistogram8(const ilImage *I){ size_t *il_histogram8(const il_Image *I){
if(!I || !I->data || I->type != IMTYPE_U8) return NULL; if(!I || !I->data || I->type != IMTYPE_U8) return NULL;
size_t *histogram = MALLOC(size_t, 256); size_t *histogram = MALLOC(size_t, 256);
int wh = I->width * I->height; int wh = I->width * I->height;
@ -277,11 +277,11 @@ size_t *ilhistogram8(const ilImage *I){
} }
/** /**
* @brief ilhistogram16 - calculate image histogram for 16-bit image * @brief il_histogram16 - calculate image histogram for 16-bit image
* @param I - orig * @param I - orig
* @return 65536 byte array * @return 65536 byte array
*/ */
size_t *ilhistogram16(const ilImage *I){ size_t *il_histogram16(const il_Image *I){
if(!I || !I->data || I->type != IMTYPE_U16) return NULL; if(!I || !I->data || I->type != IMTYPE_U16) return NULL;
size_t *histogram = MALLOC(size_t, 65536); size_t *histogram = MALLOC(size_t, 65536);
int wh = I->width * I->height; int wh = I->width * I->height;
@ -308,9 +308,9 @@ size_t *ilhistogram16(const ilImage *I){
* @param bk (o) - background value * @param bk (o) - background value
* @return 0 if error * @return 0 if error
*/ */
int ilImage_background(ilImage *img, double *bkg){ int il_Image_background(il_Image *img, double *bkg){
if(!img || !img->data || !bkg) return FALSE; if(!img || !img->data || !bkg) return FALSE;
ilImage_minmax(img); il_Image_minmax(img);
if(img->maxval == img->minval){ if(img->maxval == img->minval){
WARNX("Zero or overilluminated image!"); WARNX("Zero or overilluminated image!");
return FALSE; return FALSE;
@ -319,11 +319,11 @@ int ilImage_background(ilImage *img, double *bkg){
int histosize = 0; int histosize = 0;
switch(img->type){ switch(img->type){
case IMTYPE_U8: case IMTYPE_U8:
histogram = ilhistogram8(img); histogram = il_histogram8(img);
histosize = 256; histosize = 256;
break; break;
case IMTYPE_U16: case IMTYPE_U16:
histogram = ilhistogram16(img); histogram = il_histogram16(img);
histosize = 65536; histosize = 65536;
break; break;
default: default:
@ -375,12 +375,12 @@ int ilImage_background(ilImage *img, double *bkg){
* @param throwpart - which part of black pixels (from all amount) to throw away * @param throwpart - which part of black pixels (from all amount) to throw away
* @return allocated here image for jpeg/png storing * @return allocated here image for jpeg/png storing
*/ */
uint8_t *ilequalize8(ilImage *I, int nchannels, double throwpart){ uint8_t *il_equalize8(il_Image *I, int nchannels, double throwpart){
if(!I || !I->data || (nchannels != 1 && nchannels != 3)) return NULL; if(!I || !I->data || (nchannels != 1 && nchannels != 3)) return NULL;
ilImage_minmax(I); il_Image_minmax(I);
int width = I->width, height = I->height; int width = I->width, height = I->height;
size_t stride = width*nchannels, S = height*stride; size_t stride = width*nchannels, S = height*stride;
size_t *orig_histo = ilhistogram8(I); // original hystogram (linear) size_t *orig_histo = il_histogram8(I); // original hystogram (linear)
if(!orig_histo) return NULL; if(!orig_histo) return NULL;
uint8_t *outp = MALLOC(uint8_t, S); uint8_t *outp = MALLOC(uint8_t, S);
uint8_t eq_levls[256] = {0}; // levels to convert: newpix = eq_levls[oldpix] uint8_t eq_levls[256] = {0}; // levels to convert: newpix = eq_levls[oldpix]
@ -436,12 +436,12 @@ uint8_t *ilequalize8(ilImage *I, int nchannels, double throwpart){
* @param throwpart - which part of black pixels (from all amount) to throw away * @param throwpart - which part of black pixels (from all amount) to throw away
* @return allocated here image for jpeg/png storing * @return allocated here image for jpeg/png storing
*/ */
uint8_t *ilequalize16(ilImage *I, int nchannels, double throwpart){ uint8_t *il_equalize16(il_Image *I, int nchannels, double throwpart){
if(!I || !I->data || (nchannels != 1 && nchannels != 3)) return NULL; if(!I || !I->data || (nchannels != 1 && nchannels != 3)) return NULL;
ilImage_minmax(I); il_Image_minmax(I);
int width = I->width, height = I->height; int width = I->width, height = I->height;
size_t stride = width*nchannels, S = height*stride; size_t stride = width*nchannels, S = height*stride;
size_t *orig_histo = ilhistogram8(I); // original hystogram (linear) size_t *orig_histo = il_histogram8(I); // original hystogram (linear)
if(!orig_histo) return NULL; if(!orig_histo) return NULL;
uint8_t *outp = MALLOC(uint8_t, S); uint8_t *outp = MALLOC(uint8_t, S);
uint16_t *eq_levls = MALLOC(uint16_t, 65536); // levels to convert: newpix = eq_levls[oldpix] uint16_t *eq_levls = MALLOC(uint16_t, 65536); // levels to convert: newpix = eq_levls[oldpix]
@ -486,7 +486,7 @@ uint8_t *ilequalize16(ilImage *I, int nchannels, double throwpart){
return outp; return outp;
} }
static void u8minmax(ilImage *I){ static void u8minmax(il_Image *I){
uint8_t *data = (uint8_t*)I->data; uint8_t *data = (uint8_t*)I->data;
double min = *data, max = min; double min = *data, max = min;
int wh = I->width * I->height; int wh = I->width * I->height;
@ -508,7 +508,7 @@ static void u8minmax(ilImage *I){
I->maxval = max; I->maxval = max;
I->minval = min; I->minval = min;
} }
static void u16minmax(ilImage *I){ static void u16minmax(il_Image *I){
uint16_t *data = (uint16_t*)I->data; uint16_t *data = (uint16_t*)I->data;
double min = *data, max = min; double min = *data, max = min;
int wh = I->width * I->height; int wh = I->width * I->height;
@ -530,7 +530,7 @@ static void u16minmax(ilImage *I){
I->maxval = max; I->maxval = max;
I->minval = min; I->minval = min;
} }
static void u32minmax(ilImage *I){ static void u32minmax(il_Image *I){
uint32_t *data = (uint32_t*)I->data; uint32_t *data = (uint32_t*)I->data;
double min = *data, max = min; double min = *data, max = min;
int wh = I->width * I->height; int wh = I->width * I->height;
@ -552,7 +552,7 @@ static void u32minmax(ilImage *I){
I->maxval = max; I->maxval = max;
I->minval = min; I->minval = min;
} }
static void fminmax(ilImage *I){ static void fminmax(il_Image *I){
float *data = (float*)I->data; float *data = (float*)I->data;
double min = *data, max = min; double min = *data, max = min;
int wh = I->width * I->height; int wh = I->width * I->height;
@ -574,7 +574,7 @@ static void fminmax(ilImage *I){
I->maxval = max; I->maxval = max;
I->minval = min; I->minval = min;
} }
static void dminmax(ilImage *I){ static void dminmax(il_Image *I){
double *data = (double*)I->data; double *data = (double*)I->data;
double min = *data, max = min; double min = *data, max = min;
int wh = I->width * I->height; int wh = I->width * I->height;
@ -598,7 +598,7 @@ static void dminmax(ilImage *I){
} }
// calculate extremal values of image data and store them in it // calculate extremal values of image data and store them in it
void ilImage_minmax(ilImage *I){ void il_Image_minmax(il_Image *I){
if(!I || !I->data) return; if(!I || !I->data) return;
#ifdef EBUG #ifdef EBUG
double t0 = dtime(); double t0 = dtime();
@ -639,7 +639,7 @@ void ilImage_minmax(ilImage *I){
* @param quality - jpeg quality * @param quality - jpeg quality
* @return FALSE if failed * @return FALSE if failed
*/ */
int ilwrite_jpg(const char *name, int w, int h, int ncolors, uint8_t *bytes, int quality){ int il_write_jpg(const char *name, int w, int h, int ncolors, uint8_t *bytes, int quality){
if(!bytes || !name || quality < 5 || quality > 100 || (ncolors != 1 && ncolors != 3) || w < 1 || h < 1) return FALSE; if(!bytes || !name || quality < 5 || quality > 100 || (ncolors != 1 && ncolors != 3) || w < 1 || h < 1) return FALSE;
char *tmpnm = MALLOC(char, strlen(name) + 10); char *tmpnm = MALLOC(char, strlen(name) + 10);
sprintf(tmpnm, "%s-tmp.jpg", name); sprintf(tmpnm, "%s-tmp.jpg", name);
@ -655,13 +655,13 @@ int ilwrite_jpg(const char *name, int w, int h, int ncolors, uint8_t *bytes, int
} }
/** /**
* @brief ilImg3_jpg - save Img3 as jpeg * @brief il_Img3_jpg - save Img3 as jpeg
* @param name - output file name * @param name - output file name
* @param I3 - image * @param I3 - image
* @param quality - jpeg quality * @param quality - jpeg quality
* @return FALSE if failed * @return FALSE if failed
*/ */
int ilImg3_jpg(const char *name, ilImg3 *I3, int quality){ int il_Img3_jpg(const char *name, il_Img3 *I3, int quality){
if(!name || quality < 5 || quality > 100 || !I3 || !I3->data || I3->width < 1 || I3->height < 1) return FALSE; if(!name || quality < 5 || quality > 100 || !I3 || !I3->data || I3->width < 1 || I3->height < 1) return FALSE;
char *tmpnm = MALLOC(char, strlen(name) + 10); char *tmpnm = MALLOC(char, strlen(name) + 10);
sprintf(tmpnm, "%s-tmp.jpg", name); sprintf(tmpnm, "%s-tmp.jpg", name);
@ -685,7 +685,7 @@ int ilImg3_jpg(const char *name, ilImg3 *I3, int quality){
* @param bytes - image data * @param bytes - image data
* @return FALSE if failed * @return FALSE if failed
*/ */
int ilwrite_png(const char *name, int w, int h, int ncolors, uint8_t *bytes){ int il_write_png(const char *name, int w, int h, int ncolors, uint8_t *bytes){
if(!bytes || !name || (ncolors != 1 && ncolors != 3) || w < 1 || h < 1) return FALSE; if(!bytes || !name || (ncolors != 1 && ncolors != 3) || w < 1 || h < 1) return FALSE;
char *tmpnm = MALLOC(char, strlen(name) + 10); char *tmpnm = MALLOC(char, strlen(name) + 10);
sprintf(tmpnm, "%s-tmp.jpg", name); sprintf(tmpnm, "%s-tmp.jpg", name);
@ -701,13 +701,13 @@ int ilwrite_png(const char *name, int w, int h, int ncolors, uint8_t *bytes){
} }
/** /**
* @brief ilImg3_png - save Img3 as jpeg * @brief il_Img3_png - save Img3 as jpeg
* @param name - output file name * @param name - output file name
* @param I3 - image * @param I3 - image
* @param quality - jpeg quality * @param quality - jpeg quality
* @return FALSE if failed * @return FALSE if failed
*/ */
int ilImg3_png(const char *name, ilImg3 *I3){ int il_Img3_png(const char *name, il_Img3 *I3){
if(!name || !I3 || !I3->data || I3->width < 1 || I3->height < 1) return FALSE; if(!name || !I3 || !I3->data || I3->width < 1 || I3->height < 1) return FALSE;
char *tmpnm = MALLOC(char, strlen(name) + 10); char *tmpnm = MALLOC(char, strlen(name) + 10);
sprintf(tmpnm, "%s-tmp.png", name); sprintf(tmpnm, "%s-tmp.png", name);

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 8.0.2, 2023-03-27T14:51:54. --> <!-- Written by QtCreator 12.0.1, 2024-02-02T10:40:45. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -8,7 +8,7 @@
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value> <value type="qlonglong">0</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.EditorSettings</variable> <variable>ProjectExplorer.Project.EditorSettings</variable>
@ -28,7 +28,7 @@
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value> <value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap> </valuemap>
</valuemap> </valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value> <value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value> <value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value> <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value> <value type="int" key="EditorConfiguration.IndentSize">4</value>
@ -37,6 +37,7 @@
<value type="bool" key="EditorConfiguration.MouseHiding">true</value> <value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value> <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value> <value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value> <value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value> <value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value> <value type="bool" key="EditorConfiguration.ShowMargin">false</value>
@ -54,16 +55,29 @@
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value> <value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value> <value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value> <value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap> </valuemap>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.PluginSettings</variable> <variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"> <valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
<value type="bool" key="AutoTest.Framework.Boost">true</value>
<value type="bool" key="AutoTest.Framework.CTest">false</value>
<value type="bool" key="AutoTest.Framework.Catch">true</value>
<value type="bool" key="AutoTest.Framework.GTest">true</value>
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools"> <valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value> <value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value> <value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value> <value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">4</value> <value type="int" key="ClangTools.ParallelJobs">4</value>
<value type="bool" key="ClangTools.PreferConfigFile">false</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/> <valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/> <valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/> <valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
@ -78,9 +92,9 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/Image_processing/Image_processing_library=improclib</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/Image_processing/Image_processing_library=improclib</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
@ -91,7 +105,7 @@
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
@ -104,7 +118,7 @@
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
@ -117,10 +131,10 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value> <value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
@ -130,24 +144,28 @@
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value> <value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/> <valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value> <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap> </valuemap>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.TargetCount</variable> <variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value> <value type="qlonglong">1</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable> <variable>ProjectExplorer.Project.Updater.FileVersion</variable>

View File

@ -29,14 +29,14 @@ typedef struct{
uint8_t *data; // image data uint8_t *data; // image data
int width; // width int width; // width
int height; // height int height; // height
} ilImg3; } il_Img3;
// 1-channel image - pattern // 1-channel image - pattern
typedef struct{ typedef struct{
uint8_t *data; // image data uint8_t *data; // image data
int width; // width int width; // width
int height; // height int height; // height
} ilPattern; } il_Pattern;
typedef enum{ typedef enum{
IMTYPE_U8, // uint8_t IMTYPE_U8, // uint8_t
@ -45,17 +45,17 @@ typedef enum{
IMTYPE_F, // float IMTYPE_F, // float
IMTYPE_D, // double IMTYPE_D, // double
IMTYPE_AMOUNT IMTYPE_AMOUNT
} ilimtype_t; } il_imtype_t;
typedef struct{ typedef struct{
int width; // width int width; // width
int height; // height int height; // height
ilimtype_t type; // data type il_imtype_t type; // data type
int pixbytes; // size of one pixel data (bytes) int pixbytes; // size of one pixel data (bytes)
void *data; // picture data void *data; // picture data
double minval; // extremal data values double minval; // extremal data values
double maxval; double maxval;
} ilImage; } il_Image;
// input file/directory type // input file/directory type
typedef enum{ typedef enum{
@ -68,88 +68,88 @@ typedef enum{
T_FITS, // only to check type: FITS are supported in fitsmaniplib T_FITS, // only to check type: FITS are supported in fitsmaniplib
T_GZIP, T_GZIP,
T_AMOUNT T_AMOUNT
} ilInputType; } il_InputType;
/*================================================================================* /*================================================================================*
* converttypes.c * * converttypes.c *
*================================================================================*/ *================================================================================*/
ilImage *ilu82Image(const uint8_t *data, int width, int height); il_Image *il_u82Image(const uint8_t *data, int width, int height);
uint8_t *ilImage2u8(ilImage *I, int nchannels); uint8_t *il_Image2u8(il_Image *I, int nchannels);
ilImage *ilbin2Image(const uint8_t *image, int W, int H); il_Image *il_bin2Image(const uint8_t *image, int W, int H);
uint8_t *ilImage2bin(const ilImage *im, double bk); uint8_t *il_Image2bin(const il_Image *im, double bk);
size_t *ilbin2sizet(const uint8_t *image, int W, int H); size_t *il_bin2sizet(const uint8_t *image, int W, int H);
/*================================================================================* /*================================================================================*
* draw.c * * draw.c *
*================================================================================*/ *================================================================================*/
extern const uint8_t ilColor_red[3], ilColor_green[3], ilColor_blue[3], ilColor_black[3], ilColor_white[3]; extern const uint8_t il_Color_red[3], il_Color_green[3], il_Color_blue[3], il_Color_black[3], il_Color_white[3];
ilPattern *ilPattern_new(int w, int h); il_Pattern *il_Pattern_new(int w, int h);
void ilPattern_free(ilPattern **I); void il_Pattern_free(il_Pattern **I);
ilImg3 *ilImg3_new(int w, int h); il_Img3 *il_Img3_new(int w, int h);
void ilImg3_free(ilImg3 **I3); void il_Img3_free(il_Img3 **I3);
ilPattern *ilPattern_cross(int w, int h); il_Pattern *il_Pattern_cross(int w, int h);
ilPattern *ilPattern_xcross(int w, int h); il_Pattern *il_Pattern_xcross(int w, int h);
ilPattern *ilPattern_star(int w, int h, double fwhm, double beta); il_Pattern *il_Pattern_star(int w, int h, double fwhm, double beta);
ilImage *ilImage_star(ilimtype_t type, int w, int h, double fwhm, double beta); il_Image *il_Image_star(il_imtype_t type, int w, int h, double fwhm, double beta);
void ilImage_addsub(ilImage *img, const ilImage *p, int xc, int yc, double weight); void il_Image_addsub(il_Image *img, const il_Image *p, int xc, int yc, double weight);
void ilImage_drawpix(ilImage *I, int x, int y, const void *val); void il_Image_drawpix(il_Image *I, int x, int y, const void *val);
void ilImage_drawline(ilImage *I, int x0, int y0, int x1, int y1, const void *val); void il_Image_drawline(il_Image *I, int x0, int y0, int x1, int y1, const void *val);
void ilImage_drawcircle(ilImage *I, int x0, int y0, int R, const void *val); void il_Image_drawcircle(il_Image *I, int x0, int y0, int R, const void *val);
void ilImg3_drawpattern(ilImg3 *img, const ilPattern *p, int xc, int yc, const uint8_t color[3]); void il_Img3_drawpattern(il_Img3 *img, const il_Pattern *p, int xc, int yc, const uint8_t color[3]);
void ilImg3_setcolor(uint8_t impixel[3], const uint8_t color[3]); void il_Img3_setcolor(uint8_t impixel[3], const uint8_t color[3]);
void ilImg3_drawpix(ilImg3 *img, int x, int y, const uint8_t color[3]); void il_Img3_drawpix(il_Img3 *img, int x, int y, const uint8_t color[3]);
void ilImg3_drawline(ilImg3 *img, int x0, int y0, int x1, int y1, const uint8_t color[3]); void il_Img3_drawline(il_Img3 *img, int x0, int y0, int x1, int y1, const uint8_t color[3]);
void ilImg3_drawcircle(ilImg3 *I, int x0, int y0, int R, const uint8_t color[3]); void il_Img3_drawcircle(il_Img3 *I, int x0, int y0, int R, const uint8_t color[3]);
void ilImg3_drawgrid(ilImg3 *img, int x0, int y0, int xstep, int ystep, const uint8_t color[3]); void il_Img3_drawgrid(il_Img3 *img, int x0, int y0, int xstep, int ystep, const uint8_t color[3]);
ilImg3 *ilImg3_subimage(const ilImg3 *I, int x0, int y0, int x1, int y1); il_Img3 *il_Img3_subimage(const il_Img3 *I, int x0, int y0, int x1, int y1);
/*================================================================================* /*================================================================================*
* imagefile.c * * imagefile.c *
*================================================================================*/ *================================================================================*/
int ilgetpixbytes(ilimtype_t type); int il_getpixbytes(il_imtype_t type);
void ilImage_minmax(ilImage *I); void il_Image_minmax(il_Image *I);
uint8_t *ilequalize8(ilImage *I, int nchannels, double throwpart); uint8_t *il_equalize8(il_Image *I, int nchannels, double throwpart);
uint8_t *ilequalize16(ilImage *I, int nchannels, double throwpart); uint8_t *il_equalize16(il_Image *I, int nchannels, double throwpart);
ilInputType ilchkinput(const char *name); il_InputType il_chkinput(const char *name);
ilImage *ilImage_read(const char *name); il_Image *il_Image_read(const char *name);
ilImage *ilImage_new(int w, int h, ilimtype_t type); il_Image *il_Image_new(int w, int h, il_imtype_t type);
ilImage *ilImage_sim(const ilImage *i); il_Image *il_Image_sim(const il_Image *i);
void ilImage_free(ilImage **I); void il_Image_free(il_Image **I);
size_t *ilhistogram8(const ilImage *I); size_t *il_histogram8(const il_Image *I);
size_t *ilhistogram16(const ilImage *I); size_t *il_histogram16(const il_Image *I);
int ilImage_background(ilImage *img, double *bkg); int il_Image_background(il_Image *img, double *bkg);
ilImg3 *ilImg3_read(const char *name); il_Img3 *il_Img3_read(const char *name);
int ilImg3_jpg(const char *name, ilImg3 *I3, int quality); int il_Img3_jpg(const char *name, il_Img3 *I3, int quality);
int ilImg3_png(const char *name, ilImg3 *I3); int il_Img3_png(const char *name, il_Img3 *I3);
int ilwrite_jpg(const char *name, int w, int h, int ncolors, uint8_t *bytes, int quality); int il_write_jpg(const char *name, int w, int h, int ncolors, uint8_t *bytes, int quality);
int ilwrite_png(const char *name, int w, int h, int ncolors, uint8_t *bytes); int il_write_png(const char *name, int w, int h, int ncolors, uint8_t *bytes);
/*================================================================================* /*================================================================================*
* letters.c * * letters.c *
*================================================================================*/ *================================================================================*/
int ilImage_putstring(ilImage *I, const char *str, int x, int y); int il_Image_putstring(il_Image *I, const char *str, int x, int y);
int ilImg3_putstring(ilImg3 *I, const char *str, int x, int y, const uint8_t color[3]); int il_Img3_putstring(il_Img3 *I, const char *str, int x, int y, const uint8_t color[3]);
/*================================================================================* /*================================================================================*
* random.c * * random.c *
*================================================================================*/ *================================================================================*/
double ilNormalBase(); double il_NormalBase();
double ilNormal(double mean, double std); double il_Normal(double mean, double std);
void ilNormalPair(double *x, double *y, double xmean, double ymean, double xstd, double ystd); void il_NormalPair(double *x, double *y, double xmean, double ymean, double xstd, double ystd);
int ilPoissonSetStep(double s); int il_PoissonSetStep(double s);
int ilPoisson(double lambda); int il_Poisson(double lambda);
void ilImage_addPoisson(ilImage *I, double lambda); void il_Image_addPoisson(il_Image *I, double lambda);
void ilImg3_addPoisson(ilImg3 *I, double lambda); void il_Img3_addPoisson(il_Img3 *I, double lambda);
/*================================================================================* /*================================================================================*
* binmorph.c * * binmorph.c *
@ -165,34 +165,34 @@ typedef struct{
uint16_t ymin; uint16_t ymin;
uint16_t ymax; uint16_t ymax;
uint32_t area; // total amount of object pixels inside the box uint32_t area; // total amount of object pixels inside the box
} ilBox; } il_Box;
typedef struct{ typedef struct{
size_t Nobj; size_t Nobj;
ilBox *boxes; il_Box *boxes;
} ilConnComps; } il_ConnComps;
// morphological operations: // morphological operations:
uint8_t *ildilation(const uint8_t *image, int W, int H); uint8_t *il_dilation(const uint8_t *image, int W, int H);
uint8_t *ildilationN(const uint8_t *image, int W, int H, int N); uint8_t *il_dilationN(const uint8_t *image, int W, int H, int N);
uint8_t *ilerosion(const uint8_t *image, int W, int H); uint8_t *il_erosion(const uint8_t *image, int W, int H);
uint8_t *ilerosionN(const uint8_t *image, int W, int H, int N); uint8_t *il_erosionN(const uint8_t *image, int W, int H, int N);
uint8_t *ilopeningN(uint8_t *image, int W, int H, int N); uint8_t *il_openingN(uint8_t *image, int W, int H, int N);
uint8_t *ilclosingN(uint8_t *image, int W, int H, int N); uint8_t *il_closingN(uint8_t *image, int W, int H, int N);
uint8_t *iltopHat(uint8_t *image, int W, int H, int N); uint8_t *il_topHat(uint8_t *image, int W, int H, int N);
uint8_t *ilbotHat(uint8_t *image, int W, int H, int N); uint8_t *il_botHat(uint8_t *image, int W, int H, int N);
// logical operations // logical operations
uint8_t *ilimand(uint8_t *im1, uint8_t *im2, int W, int H); uint8_t *il_imand(uint8_t *im1, uint8_t *im2, int W, int H);
uint8_t *ilsubstim(uint8_t *im1, uint8_t *im2, int W, int H); uint8_t *il_substim(uint8_t *im1, uint8_t *im2, int W, int H);
// clear non 4-connected pixels // clear non 4-connected pixels
uint8_t *ilfilter4(uint8_t *image, int W, int H); uint8_t *il_filter4(uint8_t *image, int W, int H);
// clear single pixels // clear single pixels
uint8_t *ilfilter8(uint8_t *image, int W, int H); uint8_t *il_filter8(uint8_t *image, int W, int H);
size_t *ilCClabel4(uint8_t *Img, int W, int H, ilConnComps **CC); size_t *il_CClabel4(uint8_t *Img, int W, int H, il_ConnComps **CC);
//size_t *ilcclabel8(uint8_t *Img, int W, int H, size_t *Nobj); //size_t *il_cclabel8(uint8_t *Img, int W, int H, size_t *Nobj);
/*================================================================================* /*================================================================================*
* * * *

View File

@ -133,14 +133,14 @@ static const uint8_t letters[95][13] = {
} }
/** /**
* @brief ilImage_putstring - print text string over image * @brief il_Image_putstring - print text string over image
* @param I - image * @param I - image
* @param str - zero-terminated sring * @param str - zero-terminated sring
* @param x - x coordinate of left bottom text angle * @param x - x coordinate of left bottom text angle
* @param y - y (upside down) * @param y - y (upside down)
* @return * @return
*/ */
int ilImage_putstring(ilImage *I, const char *str, int x, int y){ int il_Image_putstring(il_Image *I, const char *str, int x, int y){
int c; int c;
if(x >= I->width || y < 1 || y > I->height + 12) return FALSE; if(x >= I->width || y < 1 || y > I->height + 12) return FALSE;
int startx = x; int startx = x;
@ -181,8 +181,8 @@ int ilImage_putstring(ilImage *I, const char *str, int x, int y){
return TRUE; return TRUE;
} }
// the same as ilImage_putstring but with given color // the same as il_Image_putstring but with given color
int ilImg3_putstring(ilImg3 *I, const char *str, int x, int y, const uint8_t color[3]){ int il_Img3_putstring(il_Img3 *I, const char *str, int x, int y, const uint8_t color[3]){
int c; int c;
if(x >= I->width || y < 1 || y > I->height + 12) return FALSE; if(x >= I->width || y < 1 || y > I->height + 12) return FALSE;
int startx = x; int startx = x;
@ -203,7 +203,7 @@ int ilImg3_putstring(ilImg3 *I, const char *str, int x, int y, const uint8_t col
uint8_t l = *letter; uint8_t l = *letter;
for(int curx = x; curx < x+8; ++curx, data+=3, l <<= 1){ if(curx >= I->width) break; if(curx < 0) continue; for(int curx = x; curx < x+8; ++curx, data+=3, l <<= 1){ if(curx >= I->width) break; if(curx < 0) continue;
if(l & 0x80){ // foreground - set to it given color or its negative if(l & 0x80){ // foreground - set to it given color or its negative
ilImg3_setcolor(data, color); il_Img3_setcolor(data, color);
} }
} }
} }

View File

@ -22,7 +22,7 @@
#include <usefull_macros.h> #include <usefull_macros.h>
// Box&Muller method for gaussian RNG (mean=0, std=1) // Box&Muller method for gaussian RNG (mean=0, std=1)
double ilNormalBase(){ double il_NormalBase(){
double U = drand48(), V = drand48(); double U = drand48(), V = drand48();
double S = sqrt(-2*log(U)); double S = sqrt(-2*log(U));
double X = S * cos(2*M_PI*V); double X = S * cos(2*M_PI*V);
@ -30,17 +30,17 @@ double ilNormalBase(){
return X * Y; return X * Y;
} }
double ilNormal(double mean, double std){ double il_Normal(double mean, double std){
return ilNormalBase() * std + mean; return il_NormalBase() * std + mean;
} }
/** /**
* @brief ilNormalPair - gaussian distributed pair of coordinates * @brief il_NormalPair - gaussian distributed pair of coordinates
* @param x,y - coordinates * @param x,y - coordinates
* @param xmean, ymean - mean of coordinated * @param xmean, ymean - mean of coordinated
* @param xstd, ystd - sigma * @param xstd, ystd - sigma
*/ */
void ilNormalPair(double *x, double *y, double xmean, double ymean, double xstd, double ystd){ void il_NormalPair(double *x, double *y, double xmean, double ymean, double xstd, double ystd){
if(!x || !y) return; if(!x || !y) return;
double U = drand48(), V = drand48(); double U = drand48(), V = drand48();
double S = sqrt(-2*log(U)); double S = sqrt(-2*log(U));
@ -50,11 +50,11 @@ void ilNormalPair(double *x, double *y, double xmean, double ymean, double xstd,
static double step = 500., es = -1.; static double step = 500., es = -1.;
/** /**
* @brief ilPoissonSetStep - change step value for ilPoisson algo * @brief il_PoissonSetStep - change step value for il_Poisson algo
* @param s - new step (>1) * @param s - new step (>1)
* @return TRUE if OK * @return TRUE if OK
*/ */
int ilPoissonSetStep(double s){ int il_PoissonSetStep(double s){
if(s < 1.){ if(s < 1.){
WARNX("ilPoissonSetStep(): step should be > 1."); WARNX("ilPoissonSetStep(): step should be > 1.");
return FALSE; return FALSE;
@ -65,11 +65,11 @@ int ilPoissonSetStep(double s){
} }
/** /**
* @brief ilPoisson - integer number with Poisson distribution * @brief il_Poisson - integer number with Poisson distribution
* @param lambda - mean (and dispersion) of distribution * @param lambda - mean (and dispersion) of distribution
* @return number * @return number
*/ */
int ilPoisson(double lambda){ int il_Poisson(double lambda){
if(es < 0.) es = exp(step); if(es < 0.) es = exp(step);
double L = lambda, p = 1.; double L = lambda, p = 1.;
int k = 0; int k = 0;
@ -93,36 +93,36 @@ int ilPoisson(double lambda){
type *d = (type*)I->data; \ type *d = (type*)I->data; \
int wh = I->width * I->height; \ int wh = I->width * I->height; \
for(int i = 0; i < wh; ++i, ++d){ \ for(int i = 0; i < wh; ++i, ++d){ \
type res = *d + ilPoisson(lambda); \ type res = *d + il_Poisson(lambda); \
*d = (res >= *d) ? res : max; \ *d = (res >= *d) ? res : max; \
} }
#define ADDPF(type) \ #define ADDPF(type) \
type *d = (type*)I->data; \ type *d = (type*)I->data; \
int wh = I->width * I->height; \ int wh = I->width * I->height; \
for(int i = 0; i < wh; ++i, ++d){ \ for(int i = 0; i < wh; ++i, ++d){ \
*d += ilPoisson(lambda); \ *d += il_Poisson(lambda); \
} }
static void add8p(ilImage *I, double lambda){ static void add8p(il_Image *I, double lambda){
ADDPU(uint8_t, 0xff); ADDPU(uint8_t, 0xff);
} }
static void add16p(ilImage *I, double lambda){ static void add16p(il_Image *I, double lambda){
ADDPU(uint16_t, 0xffff); ADDPU(uint16_t, 0xffff);
} }
static void add32p(ilImage *I, double lambda){ static void add32p(il_Image *I, double lambda){
ADDPU(uint32_t, 0xffffffff); ADDPU(uint32_t, 0xffffffff);
} }
static void addfp(ilImage *I, double lambda){ static void addfp(il_Image *I, double lambda){
ADDPF(float); ADDPF(float);
} }
static void adddp(ilImage *I, double lambda){ static void adddp(il_Image *I, double lambda){
ADDPF(double); ADDPF(double);
} }
/** /**
* @brief ilImage_addPoisson - add poisson noice to each image pixel * @brief il_Image_addPoisson - add poisson noice to each image pixel
* @param I (inout) - image * @param I (inout) - image
* @param lambda - lambda of noice * @param lambda - lambda of noice
*/ */
void ilImage_addPoisson(ilImage *I, double lambda){ void il_Image_addPoisson(il_Image *I, double lambda){
switch(I->type){ switch(I->type){
case IMTYPE_U8: case IMTYPE_U8:
return add8p(I, lambda); return add8p(I, lambda);
@ -144,13 +144,13 @@ void ilImage_addPoisson(ilImage *I, double lambda){
} }
} }
// the same as ilImage_addPoisson but for coloured image (add same noice to all three pixel colour components) // the same as il_Image_addPoisson but for coloured image (add same noice to all three pixel colour components)
void ilImg3_addPoisson(ilImg3 *I, double lambda){ void il_Img3_addPoisson(il_Img3 *I, double lambda){
int wh = I->width * I->height * 3; int wh = I->width * I->height * 3;
uint8_t *id = (uint8_t*)I->data; uint8_t *id = (uint8_t*)I->data;
//OMP_FOR() - only will be more slowly //OMP_FOR() - only will be more slowly
for(int i = 0; i < wh; i += 3){ for(int i = 0; i < wh; i += 3){
uint8_t n = ilPoisson(lambda), *d = &id[i]; uint8_t n = il_Poisson(lambda), *d = &id[i];
for(int j = 0; j < 3; ++j){ for(int j = 0; j < 3; ++j){
uint8_t newval = d[j] + n; uint8_t newval = d[j] + n;
d[j] = (newval >= d[j]) ? newval : 255; d[j] = (newval >= d[j]) ? newval : 255;