Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

 Read further if:

  • you develop or run image processing locally in bash;
  • you want to use XNAT as data source and/or remote archive;
  • you want to automate processing of multiple XNAT sessions and want to report your results in spreadsheets.
  • you want to focus on local script development and minimize programming effort to interact with XNAT.

Use case: compute BET whole brain volume for all MPRAGE scans in an MRI project in XNAT and save statistics in a spreadsheet.

1. Write a bash script that computes brain volume on a DICOM brain (assuming FSL v4+ is on the path).
in=$1 #input DICOM scan
dcm2nii $in
cp $in/[0-9]*.nii head.nii
if [ ! -f "head.nii" ]; then exit -1; fi
bet head brain -m
vol=(`fslstats brain_mask -V`); vol=${vol[1]}
#report the volume in mm3 to console.
echo $vol

2. Create a spreadsheet listing all scans that you want to process. In many cases, you'll have such spreadsheet; if not, you can start with the one created using the one generated by XNAT:

Now, modify the spreadsheet so that column names don't contain spaces, empty and irrelevant cells are removed, and change column "Scans" to "T1", with scan numbers that we want to process per each session. If any fields have trailing zeroes, you'll need to modify the csv outside of Excel to add them.

3. Now we are ready to adapt the to process all sessions from test.csv.

#this line will convert test.csv to a bash source test.params that assigns corresponding arrays.
rcsv test.csv test.params; source test.params; rm test.params

#as a result, the following arrays are assigned:
#MR_ID=("001_obscured" "002_obscured" ...
#Subject=("001" "002" "003" ...
#Scans=("SPGR" "SPGR" "SPGR" ...

#now, iterate over all MR sessions.
for ((i=0; i<${#MR_ID[*]}; i++)); do
	#this will create directory named ${MR_ID[i]} and cd to it.
	set_context ${Subject[i]} ${MR_ID[i]}
	#load specified scan from XNAT.
	load_scans "${Scans[i]}"
	#compute brain volume, similarly to
 	dcm2nii $in
	cp $in/[0-9]*.nii head.nii
	if [ ! -f "head.nii" ]; then exit -1; fi
	bet head brain -m
	vol=(`fslstats brain_mask -V`); vol=${vol[1]}
	#except, now we use special command to save a variable with this offline session.
	save_vars vol
	#uncomment the following line to test the code on a single session.

#return to the starting directory.
set_context null 

#this will go through all sessions and generate a spreadsheet summarizing variables saved with "save_vars" command.
summary mpr_vol


4. Test the batch processing.

We will run the developed script on a single session to see if it works. For that, uncomment break statement in the end of the cycle over all sessions. Now we are ready to run the script:

running brain_volume.xt

  • No labels