-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_dicoms.py
More file actions
44 lines (35 loc) · 1.7 KB
/
import_dicoms.py
File metadata and controls
44 lines (35 loc) · 1.7 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import slicer
def load_dicoms(subject_id, base_path, epoch):
subject_path = base_path
# Check if the subject folder exists
if not os.path.exists(subject_path):
print("Subject folder {subject_id} EPOCH {epoch} not found.".format(subject_id = subject_id, epoch = epoch))
return
# List all subdirectories in the subject folder
subdirectories = [d for d in os.listdir(subject_path) if os.path.isdir(os.path.join(subject_path, d))]
# Filter out folders containing "PHYSLOG"
subdirectories = [d for d in subdirectories if "PHYSLOG" not in d]
# Load DICOM files from each subdirectory
slicer.util.selectModule("DICOM")
dicomBrowser = slicer.modules.DICOMWidget.browserWidget.dicomBrowser
for subdir in subdirectories:
dicom_path = os.path.join(subject_path, subdir)
print("Loading DICOMs from: {dicom_path}".format(dicom_path = dicom_path))
dicomBrowser.importDirectory(dicom_path, dicomBrowser.ImportDirectoryAddLink)
dicomBrowser.waitForImportFinished()
#slicer.util.loadDicom(dicom_path)
if __name__ == "__main__":
# Prompt the user for a subject ID
# Specify the arbitrary base path
while True:
# Prompt the user for a subject ID
project = input("Enter project (MAP/TAP; or 'exit' to quit): ").strip()
if project.lower() == 'exit':
print("Exiting the script.")
break
subject_id = input("Enter subject ID: ").strip()
epoch = input("Enter Epoch number: ").strip()
# Call the function to load DICOMs
base_path = "/fs0/{p}/RAW/{s}/Brain/EPOCH{e}".format(p=project, s=subject_id, e=epoch)
load_dicoms(subject_id, base_path, epoch)