int main(int argc, char *argv[]) { Nrrd *info, *pos; float sigma, gthresh; char *iStr, *oStr, *sigStr, *gthStr; me = argv[0]; if (argc != 5) { usage(); } iStr = argv[1]; sigStr = argv[2]; gthStr = argv[3]; oStr = argv[4]; if (1 != sscanf(sigStr, "%g", &sigma) || 1 != sscanf(gthStr, "%g", >hresh)) { fprintf(stderr, "%s: couldn't parse %s and %s as floats\n", me, sigStr, gthStr); usage(); } if (nrrdLoad(info=nrrdNew(), iStr, NULL)) { fprintf(stderr, "%s: trouble reading \"%s\" :\n%s\n", me, iStr, biffGet(NRRD)); exit(1); } if (banePosCalc(pos = nrrdNew(), sigma, gthresh, info)) { fprintf(stderr, "%s: trouble calculating %s:\n%s\n", me, 2 == info->dim ? "p(v,g)" : "p(v)", biffGet(BANE)); exit(1); } if (nrrdSave(oStr, pos, NULL)) { fprintf(stderr, "%s: trouble writing output to \"%s\"\n", me, oStr); exit(1); } nrrdNuke(info); nrrdNuke(pos); exit(0); }
int baneGkms_pvgMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *outS, *perr, err[BIFF_STRLEN], *mapS; Nrrd *ninfo, *nposA, *nposB, *ndon, *npvg; NrrdIoState *nio; airArray *mop; int i, pret, invert, sv, sg, smlI; float *pos, p, min, max, sml, newsml, newmin, newmax; NrrdRange *range; hestOptAdd(&opt, "inv", NULL, airTypeInt, 0, 0, &invert, NULL, "Draw on white background, instead of black"); hestOptAdd(&opt, "m", "mapOut", airTypeString, 1, 1, &mapS, "", "save out the colormap used here, so that it can be applied " "to other nrrds with \"unu imap -r\""); hestOptAdd(&opt, "i", "infoIn", airTypeOther, 1, 1, &ninfo, NULL, "input info file (from \"gkms info\")", NULL, NULL, nrrdHestNrrd); hestOptAdd(&opt, "o", "imageOut", airTypeString, 1, 1, &outS, NULL, "output image, in PPM format"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_baneGkms_pvgInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); airMopAdd(mop, ndon=_baneGkmsDonNew(invert), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nposA=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nposB=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, npvg=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nio=nrrdIoStateNew(), (airMopper)nrrdIoStateNix, airMopAlways); if (airStrlen(mapS)) { if (nrrdSave(mapS, ndon, NULL)) { sprintf(err, "%s: trouble saving colormap", me); biffMove(BANE, err, NRRD); airMopError(mop); return 1; } } /* we use sigma = 1.0: different sigmas will scale the position, which will not change the coloring gthresh = 0.0: we want to see everything, and Simian has taught us that there can be boundaries at extremely low gradients */ if (banePosCalc(nposA, 1.0, 0.0, ninfo)) { sprintf(err, "%s: trouble calculating position", me); biffAdd(BANE, err); airMopError(mop); return 1; } sv = nposA->axis[0].size; sg = nposA->axis[1].size; pos = (float *)nposA->data; /* find min, max, sml, smlI: histo-eq will warp values around such that min-->min and max-->max, but 0-->??. So, find smallest magnitide position (sml) as a stand-in for 0.0 and its index (smlI) */ sml = 0; smlI = 0; min = max = AIR_NAN; for (i=0; i<sv*sg; i++) { p = pos[i]; if (!AIR_EXISTS(p)) continue; if (!AIR_EXISTS(min)) { min = max = p; sml = AIR_ABS(p); smlI = i; continue; } min = AIR_MIN(p, min); max = AIR_MAX(p, max); if (AIR_ABS(p) < sml) { sml = AIR_ABS(p); smlI = i; } } if (!AIR_EXISTS(min)) { sprintf(err, "%s: didn't see any real data in position array", me); biffAdd(BANE, err); airMopError(mop); return 1; } if (nrrdHistoEq(nposB, nposA, NULL, PVG_HISTEQ_BINS, 3, 1.0)) { sprintf(err, "%s: trouble doing histo-eq on p(v,g)", me); biffMove(BANE, err, NRRD); airMopError(mop); return 1; } /* warp position values that pos[smlI] gets mapped back to zero, and so that [newmin,newmax] is centered on zero */ pos = (float *)nposB->data; newsml = pos[smlI]; if (min < -max) { newmin = min; newmax = -min; } else { newmin = -max; newmax = max; } for (i=0; i<sv*sg; i++) { if (!AIR_EXISTS(pos[i])) { continue; } if (pos[i] < newsml) { pos[i] = AIR_CAST(float, AIR_AFFINE(min, pos[i], newsml, newmin, 0.0)); } else {