File: dcm.py

package info (click to toggle)
spyder 3.1.3+dfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,552 kB
  • ctags: 4,851
  • sloc: python: 41,887; xml: 220; makefile: 23; sh: 6
file content (26 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- coding:utf-8 -*-
"""Example of I/O plugin for loading DICOM files"""

import os.path as osp

try:
    try:
        # pydicom 0.9
        import dicom as dicomio
    except ImportError:
        # pydicom 1.0
        from pydicom import dicomio
    def load_dicom(filename):
        try:
            name = osp.splitext(osp.basename(filename))[0]
            try:
                data = dicomio.read_file(filename, force=True)
            except TypeError:
                data = dicomio.read_file(filename)                
            arr = data.pixel_array
            return {name: arr}, None
        except Exception as error:
            return None, str(error)
except ImportError:
    load_dicom = None