Created
May 29, 2014 15:32
-
-
Save ChrisBeaumont/e97d4efdc9c472836214 to your computer and use it in GitHub Desktop.
MRI Glue demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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