pip install git+https://github.com/johncolby/brats_preprocessing
import brats_preprocessing.brats_preprocessing as bp
zip_path = '/path/to/<accession>.zip'
model_path = '/path/to/model.Rdata'
mri = bp.tumor_study(zip_path=zip_path, model_path=model_path)
mri.setup()
mri.classify_series()
mri.preprocess()
These tools expect an <accession>.zip
file as input. The archive should contain a single study directory, which should in turn contain series directories, which should in turn contain DICOM files. For example, if I unzip 11111111.zip
into a directory named 11111111
, then the structure should look like:
+-11111111/
|
+-a8651ef7f70c8cba45e3141f4e3bef17/
| |
| +-06b758b1335988a09ee4cb7af3678b98/
| | |
| | +-ae01489d59eed67281e13df5ed992af0.dcm
| | |
| | +-ad08d6483cb7b02865b3b05b8003a170.dcm
| | |
| | +-... <additional files>
| |
| +-49e1e56731aac53ea1205e1f080b5c70/
| | |
| | +-268f45ba1d77340ff0fe7c4c283e6284.dcm
| | |
| | +-fb60f2e00e74a0ddc7e0f5bcaad68df6.dcm
| | |
| | +-... <additional files>
| |
| +-bfa267d60ff3e8873518773b934f99fc/
| | |
| | +-15bce104269e2c8f8cdf274845277c08.dcm
| | |
| | +-c081ec04dcade7a2643a62186374111a.dcm
| | |
| | +-... <additional files>
...
Alternatively, if air_download
is installed, you may use the download()
method to access the AIR API directly.
mri = bp.tumor_study(acc='11111111')
mri.setup()
mri.download(URL='https://air.<domain>.edu/api/', cred_path='/path/to/air_login.txt')
A small but important step in processing clinical data involves identifying the desired input series. For a given application/context, this can be done easily by training a small classifier to identify series type (e.g. axial 3D T1, FLAIR, etc.) based on DICOM header data (study code, TR, TE, series description, etc.). We do that here by loading a custom pre-trained model.Rdata
file. See URL for details.
Alternatively, series directory paths may be manually added like:
mri.add_paths(['/path/to/flair',
'/path/to/t1',
'/path/to/t1ce',
'/path/to/t2'])
Implemented with nipype
.
- DICOM files are converted to NIfTI (
dcm2niix
). - T1 processing.
- Skull strip to get
T1_brain
andT1_brain_mask
(BET
). - Register
T1_brain
to MNI template space to getT1_brain_mni
andt1_brain_mni.mat
(FLIRT
). - Apply
t1_brain_MNI.mat
transform toT1_brain_mask
(FLIRT
). - Apply final mask in MNI space (
fslmaths
).
- Skull strip to get
- Non T1 processing, e.g. FLAIR.
- Register to T1 but only save
.mat
(FLIRT
). - Concatenate FLAIR-to-T1 and T1-to-MNI transformation matrices (
convert_xfm
). - Apply concatenated
.mat
to register FLAIR to MNI in a single resampling step (FLIRT
). - Apply final mask in MNI space (
fslmaths
).
- Register to T1 but only save
- Multi-channel bias field correction (
FAST
). - Merge into single 4D file (
fslmerge
). - Change data type to 16 bit integer (
fslmaths
). - Pad voxel dimensions and reorient to BraTS template space (
FLIRT
).
MNI and BraTS template systems are different.
MNI | BraTS | |
---|---|---|
Voxel size | 1 x 1 x 1 | 1 x 1 x 1 |
Voxel dimensions | 182 x 218 x 182 | 240 x 240 x 155 |
Origin | [90, -126, -72] |
[0, 239, 0] |
Orientation | LAS (radiological) | LPS (neurological) |
Calculate voxel offsets needed to match origins between BraTS and MNI.
90 + (240 - 182) / 2 # x = 119
126 + (240 - 218) / 2 # y = 137
72 + (155 - 182) / 2 # z = 58.5
Can generate a minimal BraTS orientation template de novo like:
fslcreatehd 240 240 155 1 1 1 1 1 119 137 59 4 brats_ref
fslorient -setsformcode 1 brats_ref
fslorient -forceneurological brats_ref
fslswapdim brats_ref x -y z brats_ref_reorient
This is included as brats_ref_reorient.nii.gz
To convert from MNI to BraTS template space (pad voxel dimensions and reorient), we can use FSL FLIRT:
flirt -in t1_brain_flirt -ref brats_ref_reorient -applyxfm -usesqform -out output