/* * xpsubs1.c * * subroutines for xprobe - fra(X) work */ #include #include #include #include #include "xprobe.h" /* * Smooth a histogram by applying a low pass filter, * weighted by another histogram of same length which may * be regarded as a measure of confidence in the first * histogram's values. Type 1 histograms only. */ whistosmooth(histo, whisto, iterations) struct object *histo, *whisto; { register int *iv, *wv; register int i, k, kwas, n; int w, wwas, wsum; struct histogramdomain *hdom, *wdom; hdom = (struct histogramdomain *) histo->idom; if (hdom->type != 1) return(1); wdom = (struct histogramdomain *) whisto->idom; /* * iterate 1-2-1 smoothing, with tips done as 0-3-1, * and with weighting. */ for (n=0; nhv; wv = wdom->hv; kwas = *iv; wwas = *wv; wsum = 3*wwas + *(wv+1); if (wsum == 0) wsum = 1; *iv = (kwas * 3 * wwas + *(iv+1) * *(wv+1)) / wsum; iv++; wv++; for (i=2; inpoints; i++,iv++,wv++) { k = *iv; w = *wv; wsum = wwas + 2*w + *(wv+1); if (wsum == 0) wsum = 1; *iv = (kwas*wwas + 2*k*w + *(iv+1) * *(wv+1)) / wsum; kwas = k; wwas = w; } wsum = wwas + *wv * 3; if (wsum == 0) wsum = 1; *iv = (*iv * 3 * *wv + kwas * wwas) / wsum; } return(0); } int maxlocation(prof,peak) struct object *prof; int *peak; { struct histogramdomain *hdom; int *hv; int n,max,i,maxpos; hdom = (struct histogramdomain *) prof->idom; n = hdom->npoints; hv = hdom->hv; max = 0; for (i=0; i max) { max = *hv; maxpos = i; } } *peak = max; return(maxpos); } int xdecide(xfl) register struct xfeats *xfl; { if (xfl->difpos >= -4 && xfl->difpos <= 4 && xfl->relarea > 80 && xfl->relarea < 120 && xfl->deriv2 > 40 && xfl->cindexa > 30 && xfl->cindexa < 45) return(1); else return(0); } int intsort(a,b) register int *a, *b; { return(*a-*b); } int secondderiv(prof,pos,wid) struct object *prof; int pos,wid; { int diff,max, *hv; struct histogramdomain *hdom = (struct histogramdomain *)prof->idom; if (pos-wid < 0 || pos+wid > hdom->npoints-1) return(0); hv = hdom->hv; max = hv[pos]; diff = 2*max - hv[pos-wid] - hv[pos+wid]; /* diff = 100*diff/max; */ return(diff); } writexfeat(out,xf) FILE *out; register struct xfeats *xf; { fprintf(out,"%3d ",xf->number); fprintf(out,"%3d ",xf->Cbtype); fprintf(out,"%3d ",xf->relarea); fprintf(out,"%3d ",xf->cindexa); fprintf(out,"%3d ",xf->pindexa); fprintf(out,"%3d ",xf->difpos); fprintf(out,"%3d ",xf->profpeak); fprintf(out,"%3d ",xf->deriv2); fprintf(out,"%3d ",xf->objpeak); fprintf(out,"%3d ",xf->objmedian); fprintf(out,"\n"); } greyhistofeats(obj,xf) struct object *obj; struct xfeats *xf; { struct object *histo(),*h; struct histogramdomain *hdom; int i,j,k,n,med,perc99_5,*hv,sum; h = histo(obj); hdom = (struct histogramdomain *) h->idom; hv = hdom->hv; n = hdom->npoints; sum = 0; for (i=0; ihv; i = 0; med = sum/2; while (med > 0) { med -= *hv++; i++; } xf->objmedian = i; hv = hdom->hv + n - 1; i = n; perc99_5 = (sum + 100) / 200; while (perc99_5 > 0) { perc99_5 -= *hv--; i--; } xf->objpeak = i; } /* * normalise histogram so that max value becomes 127 */ histonormalise(obj) struct object *obj; { register struct histogramdomain *hdom; register int i, maxh, *h; hdom = (struct histogramdomain *) obj->idom; h = hdom->hv; maxh = 0; for (i=0; inpoints; i++) { if (*h > maxh) maxh = *h; h++; } h = hdom->hv; for (i=0; inpoints; i++) { *h = *h * 127 / maxh; h++; } } /* * normalise histogram so that mean value becomes 63 */ pchistonormalise(obj) struct object *obj; { register struct histogramdomain *hdom; register int i, maxh, *h; hdom = (struct histogramdomain *) obj->idom; h = hdom->hv; maxh = 0; for (i=0; inpoints; i++,h++) maxh += *h; maxh /= hdom->npoints; h = hdom->hv; for (i=0; inpoints; i++) { *h = *h * 63 / maxh; h++; } }