From: <kin...@us...> - 2003-10-30 21:35:28
|
Update of /cvsroot/teem/teem/src/nrrd In directory sc8-pr-cvs1:/tmp/cvs-serv26362/nrrd Modified Files: filt.c nrrd.h Log Message: API CHANGE: nrrd: nrrdCheapMedian now takes a new argument, "pad", which tells it to pad the input by the radius of the filter, prior to filtering, and then crops the output. Without this, the samples along the boundary are left unprocessed. Note: this functionality has migrated from "unu cmedian" down into nrrd. "unu cmedian", on the other hand, has a new command-line flag, "-c", which tells it to slice along axis 0, run filtering on all slices, and then join the results together. I was too chicken to add this the nrrd API directly, but it may migrate there. Index: filt.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/filt.c,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** filt.c 12 Sep 2003 12:10:05 -0000 1.37 --- filt.c 30 Oct 2003 21:35:24 -0000 1.38 *************** *** 304,314 **** */ int ! nrrdCheapMedian(Nrrd *nout, const Nrrd *nin, ! int mode, int radius, float wght, int bins) { char me[]="nrrdCheapMedian", func[]="cmedian", err[AIR_STRLEN_MED]; NrrdRange *range; float *hist; ! if (!(nin && nout)) { sprintf(err, "%s: got NULL pointer", me); biffAdd(NRRD, err); return 1; --- 304,317 ---- */ int ! nrrdCheapMedian(Nrrd *_nout, const Nrrd *_nin, ! int pad, int mode, ! int radius, float wght, int bins) { char me[]="nrrdCheapMedian", func[]="cmedian", err[AIR_STRLEN_MED]; NrrdRange *range; float *hist; + Nrrd *nout, *nin; + airArray *mop; ! if (!(_nin && _nout)) { sprintf(err, "%s: got NULL pointer", me); biffAdd(NRRD, err); return 1; *************** *** 322,335 **** biffAdd(NRRD, err); return 1; } ! if (!(AIR_IN_CL(1, nin->dim, 3))) { sprintf(err, "%s: sorry, can only handle dim 1, 2, 3 (not %d)", ! me, nin->dim); biffAdd(NRRD, err); return 1; } ! if (nout == nin) { sprintf(err, "%s: nout==nin disallowed", me); biffAdd(NRRD, err); return 1; } ! if (nrrdTypeBlock == nin->type) { sprintf(err, "%s: can't filter nrrd type %s", me, airEnumStr(nrrdType, nrrdTypeBlock)); --- 325,338 ---- biffAdd(NRRD, err); return 1; } ! if (!(AIR_IN_CL(1, _nin->dim, 3))) { sprintf(err, "%s: sorry, can only handle dim 1, 2, 3 (not %d)", ! me, _nin->dim); biffAdd(NRRD, err); return 1; } ! if (_nout == _nin) { sprintf(err, "%s: nout==nin disallowed", me); biffAdd(NRRD, err); return 1; } ! if (nrrdTypeBlock == _nin->type) { sprintf(err, "%s: can't filter nrrd type %s", me, airEnumStr(nrrdType, nrrdTypeBlock)); *************** *** 337,349 **** } if (nrrdCopy(nout, nin)) { ! sprintf(err, "%s: failed to create copy of input", me); ! biffAdd(NRRD, err); return 1; } range = nrrdRangeNewSet(nin, nrrdBlind8BitRangeFalse); if (!(hist = (float*)calloc(bins, sizeof(float)))) { sprintf(err, "%s: couldn't allocate histogram (%d bins)", me, bins); ! biffAdd(NRRD, err); return 1; } if (!AIR_EXISTS(wght)) wght = 1.0; --- 340,369 ---- } + mop = airMopNew(); + /* set nin based on _nin */ + airMopAdd(mop, nin=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); + if (pad) { + airMopAdd(mop, nout=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); + if (nrrdSimplePad(nin, _nin, radius, nrrdBoundaryBleed)) { + sprintf(err, "%s: trouble padding input", me); + biffAdd(NRRD, err); airMopError(mop); return 1; + } + } else { + if (nrrdCopy(nin, _nin)) { + sprintf(err, "%s: trouble copying input", me); + biffAdd(NRRD, err); airMopError(mop); return 1; + } + nout = _nout; + } if (nrrdCopy(nout, nin)) { ! sprintf(err, "%s: failed to create initial copy of input", me); ! biffAdd(NRRD, err); airMopError(mop); return 1; } range = nrrdRangeNewSet(nin, nrrdBlind8BitRangeFalse); if (!(hist = (float*)calloc(bins, sizeof(float)))) { sprintf(err, "%s: couldn't allocate histogram (%d bins)", me, bins); ! biffAdd(NRRD, err); airMopError(mop); return 1; } + airMopAdd(mop, hist, airFree, airMopAlways); if (!AIR_EXISTS(wght)) wght = 1.0; *************** *** 361,365 **** sprintf(err, "%s: sorry, %d-dimensional median unimplemented", me, nin->dim); ! biffAdd(NRRD, err); return 1; } --- 381,385 ---- sprintf(err, "%s: sorry, %d-dimensional median unimplemented", me, nin->dim); ! biffAdd(NRRD, err); airMopError(mop); return 1; } *************** *** 368,376 **** mode, radius, wght, bins)) { sprintf(err, "%s:", me); ! biffAdd(NRRD, err); return 1; } nrrdPeripheralInit(nout); ! AIR_FREE(hist); return 0; } --- 388,406 ---- mode, radius, wght, bins)) { sprintf(err, "%s:", me); ! biffAdd(NRRD, err); airMopError(mop); return 1; } nrrdPeripheralInit(nout); ! /* set _nout based on nout */ ! if (pad) { ! if (nrrdSimpleCrop(_nout, nout, radius)) { ! sprintf(err, "%s: trouble cropping output", me); ! biffAdd(NRRD, err); airMopError(mop); return 1; ! } ! } else { ! /* we've already set output in _nout == nout */ ! } ! ! airMopOkay(mop); return 0; } Index: nrrd.h =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/nrrd.h,v retrieving revision 1.118 retrieving revision 1.119 diff -C2 -d -r1.118 -r1.119 *** nrrd.h 3 Oct 2003 10:58:24 -0000 1.118 --- nrrd.h 30 Oct 2003 21:35:24 -0000 1.119 *************** *** 763,767 **** /* filt.c */ extern int nrrdCheapMedian(Nrrd *nout, const Nrrd *nin, ! int mode, int radius, float wght, int bins); /* --- 763,768 ---- /* filt.c */ extern int nrrdCheapMedian(Nrrd *nout, const Nrrd *nin, ! int pad, int mode, ! int radius, float wght, int bins); /* |