FSL: fslstats memory usage

Hi all,

I’m switching over to Susan-smoothing for my post-FMRIPREP pipeline, and running into an issue. Susan smoothing needs a parameter, for brightness threshold. Per this post, I’m trying to calculate the median brain intensity within and outside the brain mask supplied by FMRIPREP/BET.

My command to do so is as follows:

funcdir=$(dirname $f)
mask="$(ls $funcdir | grep "mask.nii.gz")"
inv="$(ls $funcdir | grep "mask_inverse.nii.gz")"
a=$(fslstats $f -p 50 -k $funcdir/$mask)
b=$(fslstats $f -p 50 -k $funcdir/$inv)
c=$($a - $b)

fslstats does not seem able to run the command to obtain the median voxel intensity with a reasonable amount of memory. I’ve tried with 10G, 20G, and 30G, and have maxed usage in each case. It doesn’t seem to me like this should take this much memory to begin with. I’m doing this on just 1 scan for now, but that code is part of a shell script that submits the SUSAN smoothing itself with those parameters to a SLURM job, 1 for each subject. Is it unreasonable to try to obtain this median statistic from an interactive job? Even then, I wasn’t expecting to need so much time/memory for this calculation.

Am I missing something?



Do the results look okay if you use the bold_ref output file to calculate the median intensity?


1 Like

Hi Steven,

Yes, I think this is the main reason for the high memory usage. Apparently doing the median voxel-wise and volume-wise is more intensive than I thought. Currently using bold_ref and getting the median value in seconds, compared to the order of 4 or 5 minutes on a high-memory node before. Should be ok, the values for the brightness threshold seem reasonable.


1 Like

For anyone who may come across this - don’t use the code I posted. It isn’t robust to cases where multiple runs were collected for a particular scan. Instead, I used sed to replace the part of the string (“preproc_bold”) with the string for naming the mask and inverse mask. I.e. something like this will work better for you:

ref=$(echo "$f" | sed "s/$substr/$repl/")

mask=$(echo "$f" | sed "s/$substr/$repl/")

inv=$(echo "$f" | sed "s/$substr/$repl/")

and so on. Cheers!