void LGCheckGrammar::p_prod (int p, int dot, char *before) { int t, u, d; if (p < 0) { p = -p; prt_log ("%s%s -> ", before, head_name [head_sym [p]]); } else { prt_log ("%s%5d %s -> ", before, p, head_name [head_sym [p]]); } t = f_tail [p]; u = l_tail [p]; d = t + dot; if (dot == -1) d = u; for (;;) { if (t == d) prt_sta (". "); if (t >= u) break; p_sym (tail [t], " "); t++; } prt_log ("\n"); }
// apply a morphologic operation to I (of size nc x nr), using the structuring element S (size se_nc x se_nr) // The shape of the structuring element is given by the non-zero pixels of S, the center of the structuring element is (ctr_c,ctr_r). // The operation is indicated with the string opetarion : min, max, median, average, random // The boundaries of the image are symmetrized, and all the arrays are stored in row major order. void morphoop(float *ptrI, int nc, int nr, float *ptrS, int se_nc, int se_nr, int ctr_c, int ctr_r, char* operation, float *ptrO) { int n, m, k, l, kmax, kmin, lmax, lmin; float pdata[se_nr*se_nc], S; kmin = -ctr_r; // rows kmax = se_nr-1-ctr_r; lmin = -ctr_c; // columns lmax = se_nc-1-ctr_c; // symmetric boundaries for (n = 0; n < nr; n++) // rows for (m = 0; m < nc; m++) // columns { // scan the structuring element and store the values in pdata int i=0; for (k = kmin; k <= kmax; k++) // rows for (l = lmin; l <= lmax; l++) // columns if(ptrS[se_nc*(k-kmin) + (l-lmin)]) { float v = ptrI[ p_sym(nc, nr, (m + l), (n + k))]; if (!isnan(v)) pdata[i++] = v; } if(strcmp(operation,"min")==0) { S = op_min(pdata, i); } else if(strcmp(operation,"max")==0) { S = op_max(pdata, i); } else if(strcmp(operation,"median")==0) { S = op_median(pdata, i); } else if(strcmp(operation,"average")==0) { S = op_average(pdata, i); } else if(strcmp(operation,"random")==0) { S = op_random(pdata, i); } else if(strcmp(operation,"rank")==0) { S = op_rank(pdata, i, ptrI[ p_sym(nc, nr, m, n) ]); } else { fprintf(stderr,"unknown operation: %s", operation); exit(1); } if (i!=0) *ptrO++ = (float) S; else *ptrO++ = NAN; } }