Created
February 10, 2022 18:39
-
-
Save dmd/a460497df4a216c30ffb43d330cfad03 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import pydicom | |
import glob | |
import os | |
import shutil | |
thedicomfiles = glob.glob(os.path.join('/input', '*.dcm')) | |
for thisfilename in thedicomfiles: | |
plan=pydicom.read_file(thisfilename) | |
outputname = [] | |
outputname.append(str(plan.PatientName)) | |
outputname.append('MR') | |
outputname.append(str(plan.SeriesNumber).zfill(4)) | |
outputname.append(str(plan.AcquisitionNumber).zfill(4)) | |
acqdate = str(plan.AcquisitionDate) | |
acqtime = str(plan.AcquisitionTime) | |
outputname += [acqdate[0:4], acqdate[4:6], acqdate[6:8]] | |
outputname += [acqtime[0:2], acqtime[2:4], acqtime[4:]] | |
instancenum = str(plan.InstanceNumber) | |
outputname.append(str(plan.InstanceNumber).zfill(9)) | |
outputname += ['IMA'] | |
imaname = os.path.join('/output', '.'.join(outputname)) | |
shutil.copyfile(thisfilename, imaname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment