Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MRI Glue demo
# -*- coding: utf-8 -*-
"""
This script loads a Brain Tumor DICOM dataset into Glue.
The data comes from http://www.osirix-viewer.com/datasets/DATA/BRAINIX.zip
To run this locally, download and unzip that file, and run this script
from the directory that you dowloaded the ZIP file to
This requires the dicom library, which you can install via
pip install pydicom
"""
from glob import glob
from glue import qglue
from dicom import read_file
import numpy as np
def load(pth):
ds = read_file(pth)
shp = ds.Rows, ds.Columns
return np.fromstring(ds.PixelData, dtype=np.short).reshape(shp)
datasets = {}
base = 'BRAINIX/BRAINIX/IRM cérébrale, neuro-crâne/'
subdirs = ['SOUS - 702',
'T1-SE-extrp - 601',
'T2W-FE-EPI - 501',
'sT2W-FLAIR - 401',
'T1-3D-FFE-C - 801',
'T1-SE-extrp - 701',
'sT2-TSE-T - 301'
]
for dir in subdirs:
slices = glob(base + dir + '/*dcm')
data = [load(s) for s in slices] # read each slice
data = np.dstack(data).transpose((2, 0, 1)) # assemble into cube
datasets[dir] = {'value': data}
qglue(**datasets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.