[637b40]: / notebooks / process_inference.py

Download this file

29 lines (24 with data), 576 Bytes

 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
# %%
# process studies into descriptive directories
from pathlib import Path
import pydicom
import os
import shutil
dir = Path("select_two/OUTSIDE")
out_dir = Path("select_two/processed")
files = list(dir.glob("**/*"))
print(len(files))
# %%
for f in files:
try:
d = pydicom.read_file(f)
os.makedirs(
str(out_dir / d.PatientID / d.SeriesDescription), exist_ok=True
)
print(d.PatientID)
shutil.copy(
f, out_dir / d.PatientID / d.SeriesDescription / f"{f.name}.dcm"
)
except:
pass
# %%