예제 #1
0
#-*- coding: MS949 -*- 
'''
  Copyright 2010, Kim, Tae-Sung. All rights reserved.
  See copyright.txt for details
'''
__author__ = 'Kim Tae-Sung'
__id__ = '$Id$'


import sys
import dicom

if len(sys.argv) < 3:
    print 'python makedicomdir.py basedirpath dicomdir_name'
    sys.exit()

try:
    ddobj = dicom.dicomfile()
    dicom.build_dicomdir(ddobj, sys.argv[1])
    ddobj.write_to_file(sys.argv[2])
    print "DICOMDIR file is successfully built and "\
          "is written to '%s'."%(sys.argv[2]) 
except RuntimeError, e:
    print 'Error in build DICOMDIR'
    print e
예제 #2
0
'''
  Copyright 2010, Kim, Tae-Sung. All rights reserved.
  See copyright.txt for details
'''
__author__ = 'Kim Tae-Sung'
__id__ = '$Id$'


import sys
import dicom

if len(sys.argv) < 2:
    print 'python dumpdicomdir.py dicomdir_name'
    sys.exit()

dfo = dicom.dicomfile(sys.argv[1])
ds = dfo['OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity'].to_dataset()

def proc_branch(ds, prefix=''):
    while True:
        print prefix, #'%04XH'%(ds['RecordInUseFlag'].get_value()), # retired!
        print ds['DirectoryRecordType'].get_value().__repr__(),
        
        if ds['DirectoryRecordType'].get_value() == 'PATIENT':
            print ds['PatientName'].get_value().__repr__(),
            print ds['PatientID'].get_value().__repr__(),
        elif ds['DirectoryRecordType'].get_value() == 'STUDY':
            print ds['StudyDate'].get_value().__repr__(),
            print ds['StudyTime'].get_value().__repr__(),
            print ds['StudyID'].get_value().__repr__(),
            print ds['StudyDescription'].get_value().__repr__(), # optional
예제 #3
0
def ex_dicom_to_numpy(fn):
    dfo = dicom.dicomfile(fn)
    a = dfo.to_numpy_array()
예제 #4
0
            continue
        kvlist.append([k.strip(' "\' '), vr, v.split('#')[0].strip()])

# PROCESS FILE LIST ARG
morefnlist = []
for fn in fnlist[:]:
    if '*' in fn or '?' in fn:
        morefnlist += glob.glob(fn)
        fnlist.remove(fn)
fnlist += morefnlist

# PROCESS EACH FILES
replacer = re.compile(r'\[\'[0-9a-fA-F\.]*\'\]')
for fn in fnlist:
    try:
        df = dicom.dicomfile(fn)
    except:
        print 'Error while loading '+fn
        continue
    
    for tag, vr, v in kvlist:
        print fn+':'+tag+' =',
        v = replacer.sub(lambda m: df.get_dataelement(m.group()[2:-2]).to_string(), v)
        el = df.get_dataelement(tag)
        print el.to_string(),'=>',
        el = df.add_dataelement(tag)
        if vr in [dicom.VR_SL, dicom.VR_SS, dicom.VR_UL, dicom.VR_US,
                  dicom.VR_AT, dicom.VR_IS]:
            if v[0] == '[' and v[-1] == ']': # this is list
                v = map(int, v[1:-1].split(','))
                el.from_long_values(v)
예제 #5
0
def ex_dicom_to_pil(fn):
    dfo = dicom.dicomfile(fn)
    im = dfo.to_pil_image()
    im.show()