Skip to content

Commit 6182fa3

Browse files
committed
forgot a dicom wrapper
1 parent ffb8472 commit 6182fa3

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

examples/dicom_wrapper.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# encoding: utf-8
2+
import SimpleITK as sitk
3+
import logging
4+
import dicom
5+
6+
logger = logging.getLogger(__name__)
7+
8+
def read_dicom_series(folder):
9+
"""Read a folder with DICOM files and outputs a SimpleITK image.
10+
Assumes that there is only one DICOM series in the folder.
11+
12+
Parameters
13+
----------
14+
folder : string
15+
Full path to folder with dicom files.
16+
17+
Returns
18+
-------
19+
SimpleITK image.
20+
"""
21+
reader = sitk.ImageSeriesReader()
22+
series_ids = reader.GetGDCMSeriesIDs(folder.encode('ascii'))
23+
24+
assert len(series_ids) == 1, 'Assuming only one series per folder.'
25+
26+
filenames = reader.GetGDCMSeriesFileNames(folder, series_ids[0],
27+
False, # useSeriesDetails
28+
False, # recursive
29+
True) # load sequences
30+
reader.SetFileNames(filenames)
31+
image = reader.Execute()
32+
33+
logger.info('Read DICOM series from {} ({} files).\nSize: {}\n'
34+
'Spacing: {}'.format(folder, len(filenames),
35+
image.GetSize(), image.GetSpacing()))
36+
37+
return image

examples/resample_isotropically.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# encoding: utf-8
2-
"""A an example to read in a image file, and resample the image to a new grid.
2+
"""An example to read in a image file, and resample the image to a new grid.
33
"""
44

55
import SimpleITK as sitk
@@ -23,7 +23,6 @@
2323
}
2424

2525

26-
2726
def resample_sitk_image(sitk_image, spacing=None, interpolator=None,
2827
fill_value=0):
2928
"""Resamples an ITK image to a new grid. If no spacing is given,

examples/resample_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import os
2222
from glob import glob
2323
import dicom
24-
from dicom import read_dicom_series
24+
from dicom_wrapper import read_dicom_series
2525
from resample_isotropically import resample_sitk_image
2626

2727
import logging

0 commit comments

Comments
 (0)