hlnicholls commited on
Commit
254ad5e
·
verified ·
1 Parent(s): 8d96ba4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -35
app.py CHANGED
@@ -23,11 +23,9 @@ if page == "Old DICOM Viewer (May 2024)":
23
 
24
  st.header("Single DICOM Image from folder 00002067")
25
  if os.path.exists(single_image_directory):
26
- single_image_files = [
27
- os.path.join(single_image_directory, f)
28
- for f in os.listdir(single_image_directory)
29
- if os.path.isfile(os.path.join(single_image_directory, f))
30
- ]
31
  if single_image_files:
32
  ds = pydicom.dcmread(single_image_files[0])
33
  single_image = ds.pixel_array
@@ -42,16 +40,14 @@ if page == "Old DICOM Viewer (May 2024)":
42
 
43
  st.header("Browse Multiple DICOM Images from 00007FA6")
44
  if os.path.exists(multiple_images_directory):
45
- multiple_image_files = [
46
- os.path.join(multiple_images_directory, f)
47
- for f in os.listdir(multiple_images_directory)
48
- if os.path.isfile(os.path.join(multiple_images_directory, f))
49
- ]
50
  if multiple_image_files:
51
  multiple_image_files.sort(key=lambda x: get_slice_location(x))
52
  dicom_images = [pydicom.dcmread(file).pixel_array for file in multiple_image_files]
53
  st.subheader("Display with Image Slider:")
54
- image_index = st.slider("Select Image Index", 0, len(dicom_images)-1, 0)
55
  fig, ax = plt.subplots()
56
  ax.imshow(dicom_images[image_index], cmap='gray')
57
  ax.axis('off')
@@ -65,11 +61,9 @@ elif page == "New DICOM Viewer (October 2024)":
65
  st.title("CBCT Viewer for 2024-10-15")
66
  new_data_directory = "20241015/"
67
  if os.path.exists(new_data_directory):
68
- new_image_files = [
69
- os.path.join(new_data_directory, f)
70
- for f in os.listdir(new_data_directory)
71
- if os.path.isfile(os.path.join(new_data_directory, f)) and f.endswith('.dcm')
72
- ]
73
  if new_image_files:
74
  new_image_files.sort(key=lambda x: int(os.path.splitext(os.path.basename(x))[0]))
75
  dicom_datasets = [pydicom.dcmread(file) for file in new_image_files]
@@ -77,7 +71,7 @@ elif page == "New DICOM Viewer (October 2024)":
77
  volume = np.stack(image_arrays, axis=0) # (num_slices, height, width)
78
 
79
  st.subheader("Axial View")
80
- slice_index = st.slider("Select Axial Slice", 0, volume.shape[0]-1, volume.shape[0]//2)
81
  slice_img = volume[slice_index, :, :]
82
  fig, ax = plt.subplots()
83
  ax.imshow(slice_img, cmap='gray')
@@ -89,21 +83,6 @@ elif page == "New DICOM Viewer (October 2024)":
89
  st.write("Directory 20241015 does not exist.")
90
 
91
  st.subheader("Videos")
92
- # Use an absolute path relative to the location of this script
93
- file_dir = os.path.dirname(os.path.abspath(__file__))
94
- sagittal_path = os.path.join(file_dir, "..", "CBCT_2024_sagittal.mov")
95
- coronal_path = os.path.join(file_dir, "..", "CBCT_2024_coronal.mov")
96
-
97
- if os.path.exists(sagittal_path):
98
- with open(sagittal_path, "rb") as f:
99
- sagittal_bytes = f.read()
100
- st.video(sagittal_bytes)
101
- else:
102
- st.error(f"Video file not found: {sagittal_path}")
103
-
104
- if os.path.exists(coronal_path):
105
- with open(coronal_path, "rb") as f:
106
- coronal_bytes = f.read()
107
- st.video(coronal_bytes)
108
- else:
109
- st.error(f"Video file not found: {coronal_path}")
 
23
 
24
  st.header("Single DICOM Image from folder 00002067")
25
  if os.path.exists(single_image_directory):
26
+ single_image_files = [os.path.join(single_image_directory, f)
27
+ for f in os.listdir(single_image_directory)
28
+ if os.path.isfile(os.path.join(single_image_directory, f))]
 
 
29
  if single_image_files:
30
  ds = pydicom.dcmread(single_image_files[0])
31
  single_image = ds.pixel_array
 
40
 
41
  st.header("Browse Multiple DICOM Images from 00007FA6")
42
  if os.path.exists(multiple_images_directory):
43
+ multiple_image_files = [os.path.join(multiple_images_directory, f)
44
+ for f in os.listdir(multiple_images_directory)
45
+ if os.path.isfile(os.path.join(multiple_images_directory, f))]
 
 
46
  if multiple_image_files:
47
  multiple_image_files.sort(key=lambda x: get_slice_location(x))
48
  dicom_images = [pydicom.dcmread(file).pixel_array for file in multiple_image_files]
49
  st.subheader("Display with Image Slider:")
50
+ image_index = st.slider("Select Image Index", 0, len(dicom_images) - 1, 0)
51
  fig, ax = plt.subplots()
52
  ax.imshow(dicom_images[image_index], cmap='gray')
53
  ax.axis('off')
 
61
  st.title("CBCT Viewer for 2024-10-15")
62
  new_data_directory = "20241015/"
63
  if os.path.exists(new_data_directory):
64
+ new_image_files = [os.path.join(new_data_directory, f)
65
+ for f in os.listdir(new_data_directory)
66
+ if os.path.isfile(os.path.join(new_data_directory, f)) and f.endswith('.dcm')]
 
 
67
  if new_image_files:
68
  new_image_files.sort(key=lambda x: int(os.path.splitext(os.path.basename(x))[0]))
69
  dicom_datasets = [pydicom.dcmread(file) for file in new_image_files]
 
71
  volume = np.stack(image_arrays, axis=0) # (num_slices, height, width)
72
 
73
  st.subheader("Axial View")
74
+ slice_index = st.slider("Select Axial Slice", 0, volume.shape[0] - 1, volume.shape[0] // 2)
75
  slice_img = volume[slice_index, :, :]
76
  fig, ax = plt.subplots()
77
  ax.imshow(slice_img, cmap='gray')
 
83
  st.write("Directory 20241015 does not exist.")
84
 
85
  st.subheader("Videos")
86
+ # Use the MP4 versions of the videos for better browser compatibility.
87
+ st.video("CBCT_2024_sagittal.mp4")
88
+ st.video("CBCT_2024_coronal.mp4")