Skip to content

Commit bd3e088

Browse files
committed
added support for synthesizing random distance maps to expand to (for
1 parent 78fe20d commit bd3e088

File tree

1 file changed

+75
-7
lines changed

1 file changed

+75
-7
lines changed

mris_expand/mris_expand.cpp

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "const.h"
3737
#include "timer.h"
3838
#include "version.h"
39+
#include "randomfields.h"
3940

4041
int main(int argc, char *argv[]) ;
4142
static int get_option(int argc, char *argv[]) ;
@@ -47,7 +48,12 @@ static int use_thickness = 0 ;
4748
static int nsurfaces = 1 ;
4849
static const char *thickness_name = "thickness" ;
4950
static const char *pial_name = "pial" ;
50-
static const char *tmap_fname = NULL ;
51+
static char *tmap_fname = NULL ;
52+
static char *tmap_write_fname = NULL ;
53+
static float tmap_std = 0.0 ;
54+
static float tmap_min = .25 ;
55+
static float tmap_max = .75 ;
56+
static int tmap_avgs = 0 ;
5157
static int nbrs = 2 ;
5258

5359
static char *orig_name = NULL ;
@@ -173,12 +179,50 @@ main(int argc, char *argv[])
173179
parms.mri_dtrans = MRIread(tmap_fname);
174180
if (parms.mri_dtrans == NULL)
175181
ErrorExit(ERROR_NOFILE,
176-
"%s: could not tmap vertex percentages from %s\n", Progname, tmap_fname) ;
182+
"%s: could not read tmap vertex percentages from %s\n", Progname, tmap_fname) ;
177183
if (parms.mri_dtrans->width != mris->nvertices)
178184
ErrorExit(ERROR_NOFILE,
179-
"%s: could not tmap width %d != mris->nvertices %d in %s\n",
185+
"%s: tmap width %d != mris->nvertices %d in %s\n",
180186
Progname, parms.mri_dtrans->width, mris->nvertices, tmap_fname) ;
181-
printf("setting vno distance to %f\n", MRIgetVoxVal(parms.mri_dtrans, 0, 0, 0, 0));
187+
}
188+
else if (!FZERO(tmap_std)) // create a random map of distances
189+
{
190+
RFS *rfs = RFspecInit(0, NULL);
191+
int vno ;
192+
193+
parms.mri_dtrans = MRIalloc(mris->nvertices, 1, 1, MRI_FLOAT) ;
194+
if (parms.mri_dtrans == NULL)
195+
ErrorExit(ERROR_NOFILE,
196+
"%s: could not allocate tmap vertex percentages from %s\n", Progname, tmap_fname) ;
197+
198+
printf("creating random tmap distances\n") ;
199+
rfs->name = strcpyalloc("gaussian");
200+
rfs->params[0] = mm_out ; // mean is halfway through the ribbon
201+
rfs->params[1] = tmap_std; // std
202+
203+
for (vno = 0 ; vno < mris->nvertices ; vno++)
204+
mris->vertices[vno].val = RFdrawVal(rfs);
205+
206+
MRISaverageVals(mris, tmap_avgs) ;
207+
for (vno = 0 ; vno < mris->nvertices ; vno++)
208+
{
209+
float dist = mris->vertices[vno].val ;
210+
211+
dist = MIN(MAX(dist, tmap_min), tmap_max) ;
212+
if (mris->vertices[vno].ripflag)
213+
dist = 0 ;
214+
215+
if (vno == Gdiag_no)
216+
printf("vno %d: val %f, ripflag %d\n", vno, dist, mris->vertices[vno].ripflag) ;
217+
218+
mris->vertices[vno].val = dist ;
219+
MRIsetVoxVal(parms.mri_dtrans, vno, 0, 0, 0, dist) ;
220+
}
221+
if (tmap_write_fname != NULL)
222+
{
223+
printf("writing random tmap to %s\n", tmap_write_fname) ;
224+
MRISwriteValues(mris, tmap_write_fname) ;
225+
}
182226
}
183227
else
184228
parms.mri_dtrans = NULL ;
@@ -329,6 +373,12 @@ get_option(int argc, char *argv[])
329373
nargs = 1 ;
330374
fprintf(stderr, "l_surf_repulse = %2.3f\n", parms.l_surf_repulse) ;
331375
}
376+
else if (!stricmp(option, "wd"))
377+
{
378+
tmap_write_fname = argv[2] ;
379+
nargs = 1 ;
380+
fprintf(stderr, "writing random tmap to %s\n", tmap_write_fname) ;
381+
}
332382
else if (!stricmp(option, "pial"))
333383
{
334384
pial_name = argv[2] ;
@@ -338,9 +388,22 @@ get_option(int argc, char *argv[])
338388
else if (!stricmp(option, "tmap"))
339389
{
340390
use_thickness = -1 ;
341-
tmap_fname = argv[2] ;
342-
printf("reading thickness target percent map from %s\n", tmap_fname) ;
343-
nargs = 1 ;
391+
if (!stricmp(argv[2], "random"))
392+
{
393+
tmap_std = atof(argv[3]);
394+
tmap_min = atof(argv[4]);
395+
tmap_max = atof(argv[5]);
396+
tmap_avgs = atoi(argv[6]);
397+
printf("creating random tmap in [%2.2f, %2.2f] with std %2.2f and %d averages\n",
398+
tmap_min, tmap_max, tmap_std, tmap_avgs) ;
399+
nargs = 5 ;
400+
}
401+
else
402+
{
403+
tmap_fname = argv[2] ;
404+
printf("reading thickness target percent map from %s\n", tmap_fname) ;
405+
nargs = 1 ;
406+
}
344407
}
345408
else switch (toupper(*option))
346409
{
@@ -414,5 +477,10 @@ usage_exit(int code)
414477
printf(" Example: mris_expand -thickness lh.white 0.5 lh.graymid\n");
415478
printf(" Example: mris_expand -label labelfile lh.white 0.5 lh.graymid\n");
416479
printf(" Example: mris_expand -tmap thickness_pct_target.mgz lh.white 0.5 lh.graymid\n");
480+
printf(" use a prespecified map of percent thickness to compute the target locations for expansion\n");
481+
printf(" Example: mris_expand -tmap random 2 .25 .75 100 -wd tmap.mgz lh.white 0.5 lh.graymid\n");
482+
printf(" creates a random target distance map with gaussian sampling (mean=.5, std=2) and cropping to .25/.75\n");
483+
printf(" and spatial averaging 100 times (cropping is average averaging). The map will be written to \n");
484+
printf(" file tmap.mgz\n");
417485
exit(code) ;
418486
}

0 commit comments

Comments
 (0)