Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,6 @@ def dicom_to_nifti_and_display(dicom_file):
|
|
20 |
|
21 |
# Extrair o slice central da imagem DICOM
|
22 |
if len(dicom_image.shape) == 3:
|
23 |
-
# Identificar o maior eixo e extrair o slice central
|
24 |
largest_axis = np.argmax(dicom_image.shape)
|
25 |
slice_index = dicom_image.shape[largest_axis] // 2
|
26 |
if largest_axis == 0:
|
@@ -57,21 +56,21 @@ def dicom_to_nifti_and_display(dicom_file):
|
|
57 |
nifti_slice = nifti_loaded # Se for 2D, use a imagem diretamente
|
58 |
|
59 |
# Exibir as imagens usando Matplotlib
|
60 |
-
fig, axes = plt.subplots(1, 2, figsize=(
|
61 |
|
62 |
# Imagem DICOM (slice central)
|
63 |
-
axes[0].imshow(dicom_slice, cmap="gray")
|
64 |
-
axes[0].set_title("Imagem DICOM Original")
|
65 |
axes[0].axis("off")
|
66 |
|
67 |
# Imagem NIfTI (slice central)
|
68 |
-
axes[1].imshow(nifti_slice, cmap="gray")
|
69 |
-
axes[1].set_title("Imagem NIfTI Convertida")
|
70 |
axes[1].axis("off")
|
71 |
|
72 |
# Salvar a figura em um buffer temporário
|
73 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_image:
|
74 |
-
plt.savefig(temp_image.name, bbox_inches="tight")
|
75 |
plt.close(fig)
|
76 |
return temp_image.name, nifti_path
|
77 |
|
@@ -85,7 +84,7 @@ with gr.Blocks() as demo:
|
|
85 |
|
86 |
with gr.Row():
|
87 |
input_dicom = gr.File(label="Upload de Arquivo DICOM")
|
88 |
-
output_images = gr.Image(label="
|
89 |
output_nifti = gr.File(label="Download do Arquivo NIfTI")
|
90 |
|
91 |
convert_button = gr.Button("Converter e Visualizar")
|
|
|
20 |
|
21 |
# Extrair o slice central da imagem DICOM
|
22 |
if len(dicom_image.shape) == 3:
|
|
|
23 |
largest_axis = np.argmax(dicom_image.shape)
|
24 |
slice_index = dicom_image.shape[largest_axis] // 2
|
25 |
if largest_axis == 0:
|
|
|
56 |
nifti_slice = nifti_loaded # Se for 2D, use a imagem diretamente
|
57 |
|
58 |
# Exibir as imagens usando Matplotlib
|
59 |
+
fig, axes = plt.subplots(1, 2, figsize=(12, 6), constrained_layout=True)
|
60 |
|
61 |
# Imagem DICOM (slice central)
|
62 |
+
axes[0].imshow(dicom_slice, cmap="gray", aspect="auto")
|
63 |
+
axes[0].set_title("Imagem DICOM Original", fontsize=14, color="blue")
|
64 |
axes[0].axis("off")
|
65 |
|
66 |
# Imagem NIfTI (slice central)
|
67 |
+
axes[1].imshow(nifti_slice, cmap="gray", aspect="auto")
|
68 |
+
axes[1].set_title("Imagem NIfTI Convertida", fontsize=14, color="green")
|
69 |
axes[1].axis("off")
|
70 |
|
71 |
# Salvar a figura em um buffer temporário
|
72 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_image:
|
73 |
+
plt.savefig(temp_image.name, bbox_inches="tight", dpi=300) # Alta resolução
|
74 |
plt.close(fig)
|
75 |
return temp_image.name, nifti_path
|
76 |
|
|
|
84 |
|
85 |
with gr.Row():
|
86 |
input_dicom = gr.File(label="Upload de Arquivo DICOM")
|
87 |
+
output_images = gr.Image(label="Visualização das Imagens", interactive=False)
|
88 |
output_nifti = gr.File(label="Download do Arquivo NIfTI")
|
89 |
|
90 |
convert_button = gr.Button("Converter e Visualizar")
|