Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,13 +3,19 @@ import pydicom
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import os
|
5 |
|
6 |
-
def visualize_dicom_sequence(
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
for i, image in enumerate(image_sequence):
|
12 |
-
# Plot DICOM image using Matplotlib
|
13 |
fig, ax = plt.subplots()
|
14 |
ax.imshow(image, cmap=plt.cm.gray)
|
15 |
ax.axis('off')
|
@@ -18,27 +24,22 @@ def visualize_dicom_sequence(file_paths):
|
|
18 |
def main():
|
19 |
st.title("Visualizador DICOM")
|
20 |
|
21 |
-
# Upload DICOM
|
22 |
-
|
23 |
-
|
24 |
-
if uploaded_files:
|
25 |
-
file_paths = []
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
file_path = f"temp_{uploaded_file.name}"
|
31 |
-
file_paths.append(file_path)
|
32 |
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
-
# Visualize the DICOM image
|
37 |
-
visualize_dicom_sequence(
|
38 |
|
39 |
-
# Remove the temporary
|
40 |
-
|
41 |
-
os.remove(file_path)
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
main()
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import os
|
5 |
|
6 |
+
def visualize_dicom_sequence(file_path):
|
7 |
+
ds = pydicom.dcmread(file_path)
|
8 |
+
image_sequence = ds.pixel_array
|
9 |
+
|
10 |
+
if image_sequence.ndim == 2:
|
11 |
+
# Only one image in the sequence
|
12 |
+
fig, ax = plt.subplots()
|
13 |
+
ax.imshow(image_sequence, cmap=plt.cm.gray)
|
14 |
+
ax.axis('off')
|
15 |
+
st.pyplot(fig)
|
16 |
+
else:
|
17 |
+
# Multiple images in the sequence
|
18 |
for i, image in enumerate(image_sequence):
|
|
|
19 |
fig, ax = plt.subplots()
|
20 |
ax.imshow(image, cmap=plt.cm.gray)
|
21 |
ax.axis('off')
|
|
|
24 |
def main():
|
25 |
st.title("Visualizador DICOM")
|
26 |
|
27 |
+
# Upload DICOM file
|
28 |
+
uploaded_file = st.file_uploader("Selecione um arquivo DICOM", type=".dcm")
|
|
|
|
|
|
|
29 |
|
30 |
+
if uploaded_file is not None:
|
31 |
+
# Convert uploaded file to bytes
|
32 |
+
file_bytes = uploaded_file.getvalue()
|
|
|
|
|
33 |
|
34 |
+
# Save the uploaded file to a temporary location
|
35 |
+
with open("temp.dcm", "wb") as f:
|
36 |
+
f.write(file_bytes)
|
37 |
|
38 |
+
# Visualize the DICOM image sequence
|
39 |
+
visualize_dicom_sequence("temp.dcm")
|
40 |
|
41 |
+
# Remove the temporary file
|
42 |
+
os.remove("temp.dcm")
|
|
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
main()
|