Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,28 +29,25 @@ def visualize_slices(file_obj, slice_index):
|
|
29 |
slice_coronal = data[:, slice_index_coronal, :]
|
30 |
slice_sagittal = data[slice_index_sagittal, :, :]
|
31 |
|
32 |
-
# Plot the slices
|
33 |
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
|
34 |
|
35 |
-
# Axial view
|
36 |
axes[0].imshow(slice_axial, cmap='gray', aspect='auto')
|
37 |
axes[0].set_title("Axial View")
|
38 |
axes[0].axis('off')
|
39 |
|
40 |
-
|
41 |
-
axes[1].imshow(slice_coronal, cmap='gray', aspect='auto')
|
42 |
axes[1].set_title("Coronal View")
|
43 |
axes[1].axis('off')
|
44 |
|
45 |
-
|
46 |
-
axes[2].imshow(slice_sagittal.T, cmap='gray', aspect='auto')
|
47 |
axes[2].set_title("Sagittal View")
|
48 |
axes[2].axis('off')
|
49 |
|
50 |
# Convert matplotlib figure to PIL Image
|
51 |
buf = io.BytesIO()
|
52 |
plt.tight_layout()
|
53 |
-
fig.savefig(buf, format='png'
|
54 |
plt.close(fig)
|
55 |
buf.seek(0)
|
56 |
pil_img = Image.open(buf)
|
|
|
29 |
slice_coronal = data[:, slice_index_coronal, :]
|
30 |
slice_sagittal = data[slice_index_sagittal, :, :]
|
31 |
|
32 |
+
# Plot the slices with the correct aspect ratios
|
33 |
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
|
34 |
|
|
|
35 |
axes[0].imshow(slice_axial, cmap='gray', aspect='auto')
|
36 |
axes[0].set_title("Axial View")
|
37 |
axes[0].axis('off')
|
38 |
|
39 |
+
axes[1].imshow(slice_coronal.T, cmap='gray', aspect='auto', extent=[0, data.shape[0], 0, data.shape[2]])
|
|
|
40 |
axes[1].set_title("Coronal View")
|
41 |
axes[1].axis('off')
|
42 |
|
43 |
+
axes[2].imshow(slice_sagittal.T, cmap='gray', aspect='auto', extent=[0, data.shape[1], 0, data.shape[2]])
|
|
|
44 |
axes[2].set_title("Sagittal View")
|
45 |
axes[2].axis('off')
|
46 |
|
47 |
# Convert matplotlib figure to PIL Image
|
48 |
buf = io.BytesIO()
|
49 |
plt.tight_layout()
|
50 |
+
fig.savefig(buf, format='png')
|
51 |
plt.close(fig)
|
52 |
buf.seek(0)
|
53 |
pil_img = Image.open(buf)
|