-
Notifications
You must be signed in to change notification settings - Fork 3
Home
This is MATLAB code for various neuroimaging preprocessing operations (registration, reslicing, denoising, segmentation, etc.), which was originally intended for processing routine clinical data (hence the name).1 It takes as input nifti files (as .nii or .nii.gz) and produces copies of this data to which the requested preprocessing steps are applied. It additionally handles image data with paired label masks (e.g., a T1w MRI and a tumour mask (or multiple classes)), and makes sure that the resulting preprocessed data is consistent. These example use cases could be run as is, or be inspiration for more complicated preprocessing tasks. For more information, please refer to the detailed pipeline description.
The algorithm requires that the following package is on the MATLAB path (see the addpath
command):
- SPM12: Download from https://www.fil.ion.ucl.ac.uk/spm/software/spm12.
- spm_superres: Download/clone from https://github.com/brudfors/spm_superres (if you want to use the denoising or super-resolution options).
Download and unpack the .zip file and add the location to your MATLAB path.
out = RunPreproc(paths,opt)
INPUT
paths - Can be given as:
paths = im.ext,
paths = {im1.ext, ..., imN.ext}
paths = {{im1.ext, ..., imN.ext},
{'', ..., labn.ext, ..., ''}}
where valid extensions are .nii and .nii.gz, and labn.ext should
be in the same index position as the image it was labelled on.
opt - Preprocessing options
OUTPUT
out.pth.im - Cell array of paths to preprocessed image(s)
out.pth.im2d - Cell array of paths to 2D versions of preprocessed
image(s) (if opt.do.write2d = true)
out.pth.lab - Cell array of path to label image (if labels given)
out.pth.lab2d - Cell array of path to 2D version of label image (if
labels given and if opt.do.write2d = tru)
out.mat - Orientation matrices to go back to native space
orientation as:
Mc = spm_get_space(P{c});
spm_get_space(f,M{c}*Mc);
Input can be a single image paths, a cell array of image paths, or two cell arrays of corresponding base image paths and label image paths.
paths = { ...
{'/data/rawdata/sub-001/ses-001/anat/sub-001_ses-001_T1w.nii', ...
'/data/rawdata/sub-001/ses-001/anat/sub-001_ses-001_T2w.nii', ...
'/data/rawdata/sub-001/ses-001/anat/sub-001_ses-001_FLAIR.nii'}, ...
{'/data/derivatives/lesions/sub-001/ses-001/anat/sub-001_ses-001_desc-T1w_label-lesion_mask.nii', ...
'/data/derivatives/lesions/sub-001/ses-001/anat/sub-001_ses-001_desc-T2w_label-lesion_mask.nii', ...
'/data/derivatives/lesions/sub-001/ses-001/anat/sub-001_ses-001_desc-FLAIR_label-lesion_mask.nii'} ...
};
Note that the the base images in paths{1}
and the label images in paths{2}
have to be in same order. Later on, if you need to specify a reference image, you will use the index. So if you wanted the other images to be co-registered to the FLAIR image you would specify reference 3. You could also have a label image for just one of the base images, e.g., the T2w:
paths = { ...
{'/data/rawdata/sub-001/ses-001/anat/sub-001_ses-001_T1w.nii', ...
'/data/rawdata/sub-001/ses-001/anat/sub-001_ses-001_T2w.nii', ...
'/data/rawdata/sub-001/ses-001/anat/sub-001_ses-001_FLAIR.nii'}, ...
{'', ...
'/data/derivatives/lesions/sub-001/ses-001/anat/sub-001_ses-001_desc-T2w_label-lesion_mask.nii', ...
''} ...
};
Preprocessing options are entered as a MATLAB structure. Steps are selected in the opt.do
field, and further options for each step are specified in their own fields.
opt.do.coreg = true;
opt.coreg.ref = 3;
With the paths
argument above, this opt
argument will enable coregistration and use the FLAIR image as the reference.
For other options, please refer to the full description of the options structure.