Spaces:
Sleeping
Sleeping
Commit ·
ba6cfa8
1
Parent(s): c4c873f
Fix IndexError by clamping slice indices to valid range
Browse files
app.py
CHANGED
|
@@ -151,12 +151,15 @@ def create_slice_visualization(ct_data, seg_data, axis, slice_idx, alpha=0.5, sh
|
|
| 151 |
|
| 152 |
# Get the slice based on axis
|
| 153 |
if axis == "Axial":
|
|
|
|
| 154 |
ct_slice = ct_data[:, :, slice_idx]
|
| 155 |
seg_slice = seg_data[:, :, slice_idx] if seg_data is not None else None
|
| 156 |
elif axis == "Coronal":
|
|
|
|
| 157 |
ct_slice = ct_data[:, slice_idx, :]
|
| 158 |
seg_slice = seg_data[:, slice_idx, :] if seg_data is not None else None
|
| 159 |
else: # Sagittal
|
|
|
|
| 160 |
ct_slice = ct_data[slice_idx, :, :]
|
| 161 |
seg_slice = seg_data[slice_idx, :, :] if seg_data is not None else None
|
| 162 |
|
|
|
|
| 151 |
|
| 152 |
# Get the slice based on axis
|
| 153 |
if axis == "Axial":
|
| 154 |
+
slice_idx = max(0, min(slice_idx, ct_data.shape[2] - 1))
|
| 155 |
ct_slice = ct_data[:, :, slice_idx]
|
| 156 |
seg_slice = seg_data[:, :, slice_idx] if seg_data is not None else None
|
| 157 |
elif axis == "Coronal":
|
| 158 |
+
slice_idx = max(0, min(slice_idx, ct_data.shape[1] - 1))
|
| 159 |
ct_slice = ct_data[:, slice_idx, :]
|
| 160 |
seg_slice = seg_data[:, slice_idx, :] if seg_data is not None else None
|
| 161 |
else: # Sagittal
|
| 162 |
+
slice_idx = max(0, min(slice_idx, ct_data.shape[0] - 1))
|
| 163 |
ct_slice = ct_data[slice_idx, :, :]
|
| 164 |
seg_slice = seg_data[slice_idx, :, :] if seg_data is not None else None
|
| 165 |
|