void label_contours( double **data, long nx, long ny, double *contour_level, long n_contours, long label_interval, long label_offset, double xmin, double dx, double ymin, double dy ) { register long i; char s[100], format[100]; double max_contour, min_contour, value; long label_mode = 0; if (label_interval==0) return; widen_window(1); if (label_interval<0) { label_mode = 1; label_interval = -label_interval; } max_contour = -(min_contour = FLT_MAX); for (i=0; i<n_contours; i++) { if ((value=contour_level[i])>max_contour) max_contour = value; if (value<min_contour) min_contour = value; } value = fabs((max_contour-min_contour)/n_contours); if (value>1e3 || value<1e-2) strcpy(format, "$d%.2le$i"); else if (value>1e2) strcpy(format, "%.0lf"); else if (value>1e1) strcpy(format, "%.1lf"); else strcpy(format, "%.2lf"); for (i=label_offset; i<n_contours; i+=label_interval) { sprintf(s, format, value=contour_level[i]); label_contour(data, nx, ny, (double)value, s, xmin, dx, ymin, dy, 2*(double)((max_contour-min_contour)/n_contours), label_mode); } vertical_print(0); widen_window(0); }
AnimalExport ImgPUInt32 * perimeter(Img *bin) { int p,n; ImgPUInt32 *imcont, *perim; puint32 *cont; curve *hist; imcont = label_contour(bin); n = imcont->rows*imcont->cols; perim = new_img_puint32(imcont->rows,imcont->cols); hist = histogram_puint32(imcont); cont = imcont->data; for (p=0; p<n; p++) if (cont[p]) perim->data[p] = hist->Y[cont[p]]; free_curve(&hist); imfree_puint32(&imcont); return perim; }
/* TODO - label_contour is called two times; only once suffices */ AnimalExport ImgPUInt32 * msskl_difference(ann_img *aimg) { ImgPUInt32 *imcont, *immsskel, *imseed, *imperim; puint32 *seed, *cont, *perim, *pred, *label, *msskel, maxd1, maxd2, MaxD; int r,c,i,j,k,qx,qy,p,q, d1,d2, *idxlut,n; r = aimg->label->rows; c = aimg->label->cols; n = r*c; idxlut = aimg->label->lut; imcont = label_contour(aimg->img); imperim = perimeter(aimg->img); immsskel = new_img_puint32(r,c); imseed = root_map(aimg->pred); seed = imseed->data; cont = imcont->data; perim = imperim->data; msskel = immsskel->data; pred = aimg->pred->data; label = aimg->label->data; MaxD = 0; for (i=0; i<r; i++) for (j=0; j<c; j++) { p = index1(i,j,idxlut); // @@@ why eliminate the contours?? if (pred[p] != (unsigned)p) {/* Eliminates the contours and considers the side option */ maxd1 = maxd2 = 0; for (k=0; k < 4; k++) { qy = n4[k][0] + i; qx = n4[k][1] + j; if (valid_pixel(r,c,qx,qy)) { q = index1(qy,qx,idxlut); if (cont[seed[p]] == cont[seed[q]]) { // not a SKIZ d2 = label[q] - label[p]; if (d2 > (int)perim[seed[p]]-d2) d2 = (int)perim[seed[p]]-d2; if (d2 > (int)maxd2) maxd2 = (unsigned)d2; } else { // a SKIZ d1 = cont[seed[q]] - cont[seed[p]]; if (d1 > (int)maxd1) maxd1 = (unsigned)d1; } } } if (maxd1 > 0) msskel[p] = UINT_MAX; else { msskel[p] = maxd2; if (msskel[p] > MaxD) MaxD = msskel[p]; } } } for (p=0; p < n; p++) if (msskel[p] == UINT_MAX) msskel[p] = MaxD + 1; imfree_puint32(&imcont); imfree_puint32(&imperim); imfree_puint32(&imseed); return immsskel; }