Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import pydicom
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import os
|
5 |
import time
|
|
|
|
|
6 |
|
7 |
# Sidebar navigation
|
8 |
page = st.sidebar.radio("Select page", ("New DICOM Viewer (October 2024)", "Old DICOM Viewer (May 2024)"))
|
@@ -102,7 +104,7 @@ if page == "Old DICOM Viewer (May 2024)":
|
|
102 |
st.write("Directory 00007FA6 does not exist.")
|
103 |
|
104 |
elif page == "New DICOM Viewer (October 2024)":
|
105 |
-
st.title("
|
106 |
new_data_directory = "20241015/"
|
107 |
if os.path.exists(new_data_directory):
|
108 |
new_image_files = [
|
@@ -111,12 +113,31 @@ elif page == "New DICOM Viewer (October 2024)":
|
|
111 |
if os.path.isfile(os.path.join(new_data_directory, f)) and f.endswith('.dcm')
|
112 |
]
|
113 |
if new_image_files:
|
114 |
-
# Sort files based on the numeric part of the filename
|
115 |
new_image_files.sort(key=lambda x: int(os.path.splitext(os.path.basename(x))[0]))
|
116 |
dicom_images = [pydicom.dcmread(file).pixel_array for file in new_image_files]
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
fig, ax = plt.subplots()
|
119 |
-
ax.imshow(
|
120 |
ax.axis('off')
|
121 |
st.pyplot(fig)
|
122 |
else:
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import os
|
5 |
import time
|
6 |
+
import numpy as np
|
7 |
+
from scipy.ndimage import rotate
|
8 |
|
9 |
# Sidebar navigation
|
10 |
page = st.sidebar.radio("Select page", ("New DICOM Viewer (October 2024)", "Old DICOM Viewer (May 2024)"))
|
|
|
104 |
st.write("Directory 00007FA6 does not exist.")
|
105 |
|
106 |
elif page == "New DICOM Viewer (October 2024)":
|
107 |
+
st.title("CBCT Viewer for 2024-10-15")
|
108 |
new_data_directory = "20241015/"
|
109 |
if os.path.exists(new_data_directory):
|
110 |
new_image_files = [
|
|
|
113 |
if os.path.isfile(os.path.join(new_data_directory, f)) and f.endswith('.dcm')
|
114 |
]
|
115 |
if new_image_files:
|
116 |
+
# Sort files based on the numeric part of the filename
|
117 |
new_image_files.sort(key=lambda x: int(os.path.splitext(os.path.basename(x))[0]))
|
118 |
dicom_images = [pydicom.dcmread(file).pixel_array for file in new_image_files]
|
119 |
+
volume = np.stack(dicom_images, axis=0) # Create a 3D volume from the stack
|
120 |
+
|
121 |
+
view_type = st.selectbox("Select View Type", ("Axial", "Sagittal", "Coronal", "Oblique"))
|
122 |
+
if view_type == "Axial":
|
123 |
+
slice_index = st.slider("Select Axial Slice", 0, volume.shape[0]-1, volume.shape[0]//2)
|
124 |
+
slice_img = volume[slice_index, :, :]
|
125 |
+
elif view_type == "Sagittal":
|
126 |
+
col_index = st.slider("Select Sagittal Column", 0, volume.shape[2]-1, volume.shape[2]//2)
|
127 |
+
slice_img = volume[:, :, col_index]
|
128 |
+
slice_img = np.flipud(slice_img.T)
|
129 |
+
elif view_type == "Coronal":
|
130 |
+
row_index = st.slider("Select Coronal Row", 0, volume.shape[1]-1, volume.shape[1]//2)
|
131 |
+
slice_img = volume[:, row_index, :]
|
132 |
+
slice_img = np.flipud(slice_img.T)
|
133 |
+
elif view_type == "Oblique":
|
134 |
+
angle = st.slider("Select Oblique Angle", -45, 45, 0)
|
135 |
+
slice_index = st.slider("Select Slice Index for Oblique View", 0, volume.shape[0]-1, volume.shape[0]//2)
|
136 |
+
# For a simplified oblique view, rotate the selected axial slice
|
137 |
+
slice_axial = volume[slice_index, :, :]
|
138 |
+
slice_img = rotate(slice_axial, angle, reshape=False)
|
139 |
fig, ax = plt.subplots()
|
140 |
+
ax.imshow(slice_img, cmap='gray')
|
141 |
ax.axis('off')
|
142 |
st.pyplot(fig)
|
143 |
else:
|