Skip to content

Commit

Permalink
Merge pull request #239 from anbhimi/dev
Browse files Browse the repository at this point in the history
Python script to divide the DICOM's based on modality
  • Loading branch information
pradeeban authored Oct 28, 2021
2 parents 050de1e + d7d0837 commit 044d87f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions modules/workflows/ModalityGrouping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os, glob
import sys
import logging
import pydicom as pyd
import shutil

def modality_split(cold_extraction_path, modality_split_path):
# iterating through all the files in cold extraction
for root, files in os.walk(cold_extraction_path):
for file in files:
if file.endswith('.dcm'):
dcm_filename = root+'/'+file
dcm_path = '/'.join(dcm_filename.split('/')[5:])
dcm_only_folder = '/'.join(dcm_path.split('/')[:-1])
dcm_file = pyd.dcmread(dcm_filename)
dcm_modality = dcm_file.Modality

print (dcm_modality, dcm_only_folder)
isExist = os.path.exists(modality_split_path+str(dcm_modality)+'/'+str(dcm_only_folder))
if not isExist:
os.makedirs(modality_split_path+str(dcm_modality)+'/'+str(dcm_only_folder))
shutil.copy2(src=cold_extraction_path+str(dcm_path), dst=modality_split_path+str(dcm_modality)+'/'+str(dcm_only_folder)+'/'+str(dcm_path.split('/')[-1]))

if __name__ == "__main__":
cold_extraction_path = sys.argv[1]
modality_split_path = sys.argv[2]
print ('Starting Modality Grouping')
modality_split(cold_extraction_path, modality_split_path)

0 comments on commit 044d87f

Please sign in to comment.