Average T1w or T2w repetitions Bruker 7T - GarzaLab/Documentation GitHub Wiki
Because no 2 images are alike, you need to first register them as good as possible before averaging brains.
You need to have installed:
Ants
This is an example from a T1w FLASH for DBM.
New version
Gabriel Devenyi from the CobraLab supports this solution.
Create a new antsMultivariateTemplateConstruction2_rigidaverage.sh
from the original.
The new version will have the following modifications:
- Remove the Sharpen command on 275
- Write
--interpolation BSpline[5]
to every${WARP}
line
Or just download my version from here. You can copy it in your ANTs directory for easiness of use.
The script that will take care of this is located here.
Files were prepared with brkraw
and the structure should be as such:
data
├── sub-10
│ ├── ses-1
│ │ ├── anat
│ │ │ ├── sub-10_ses-1_T1w.json
│ │ │ ├── sub-10_ses-1_T1w.nii.gz
│ │ │ ├── sub-10_ses-1_T2w.json
│ │ │ └── sub-10_ses-1_T2w.nii.gz
│ │ ├── fmap
│ │ │ ├── sub-10_ses-1_fieldmap.json
│ │ │ ├── sub-10_ses-1_fieldmap.nii.gz
│ │ │ └── sub-10_ses-1_magnitude.nii.gz
│ │ └── func
│ │ ├── sub-10_ses-1_task-rest_run-1_bold.json
│ │ └── sub-10_ses-1_task-rest_run-1_bold.nii.gz
│ └── ses-2
│ ├── anat
│ │ ├── sub-10_ses-2_T1w.json
│ │ ├── sub-10_ses-2_T1w.nii.gz
│ │ ├── sub-10_ses-2_T2w.json
│ │ └── sub-10_ses-2_T2w.nii.gz
│ ├── fmap
│ │ ├── sub-10_ses-2_fieldmap.json
│ │ ├── sub-10_ses-2_fieldmap.nii.gz
│ │ └── sub-10_ses-2_magnitude.nii.gz
│ └── func
│ ├── sub-10_ses-2_task-rest_run-1_bold.json
│ └── sub-10_ses-2_task-rest_run-1_bold.nii.gz
Run the script inside your project
folder with data
in a similar structure as the tree above. In this example I'm using the data shown above:
bash rat-invivo-average.sh sub-5 ses-1 T1w
Outputs:
The script will create a folder called derivatives/sub-5/ses-1/preproc
with the following important files:
average.mnc
average.nii.gz
average.jpg
The average.mnc
file goes to the next preprocessing step. Check the Preprocessing.
Old version
Transform the nifti (Bruker2Nifti) to MNC. Separate the time using fslsplit
, then use ants.
fslsplit rat.nii.gz -t
nii2mnc rat.nii.gz rat.mnc
antsRegistration --dimensionality 3 --float 0 --output [reg_1,rat1_reg.mnc] --interpolation Linear --use-histogram-matching 0 --initial-moving-transform [rat1.mnc,rat2.mnc,1] --transform Rigid[0.1] --metric MI[rat1.mnc,rat2.mnc,1,64,None] --convergence [2000x1000x500x250x100,1e-6,10] --shrink-factors 4x3x2x1x1 -s 2x1.5x1x0.5x0vox -v
Ants changes the dimensions, so we need to change that.
mincresample -like rat2.mnc rat1_reg.mnc rat1_reg_dim.mnc
Then you average
mincaverage rat1.mnc rat2.mnc rat_out.mnc