Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -118,13 +118,14 @@ def extract_middle_slices(nifti_path, output_image_path, slice_size=180, center=
|
|
118 |
if label_components:
|
119 |
structure = generate_binary_structure(3, 3) # 3D, 26-connectivity
|
120 |
labeled_data, num_features = label(data > 0, structure=structure)
|
|
|
121 |
else:
|
122 |
labeled_data = resampled_data
|
123 |
num_features = None # Not needed if we're not labeling
|
124 |
|
125 |
# Compute or reuse the center of mass
|
126 |
if center is None:
|
127 |
-
com = center_of_mass(
|
128 |
center = np.round(com).astype(int)
|
129 |
|
130 |
# Define half the slice size
|
@@ -151,9 +152,9 @@ def extract_middle_slices(nifti_path, output_image_path, slice_size=180, center=
|
|
151 |
return padded_slice
|
152 |
|
153 |
# Extract slices
|
154 |
-
axial_slice = extract_2d_slice(
|
155 |
-
coronal_slice = extract_2d_slice(
|
156 |
-
sagittal_slice = extract_2d_slice(
|
157 |
|
158 |
# Apply rotations
|
159 |
axial_slice = np.rot90(axial_slice, k=-1)
|
|
|
118 |
if label_components:
|
119 |
structure = generate_binary_structure(3, 3) # 3D, 26-connectivity
|
120 |
labeled_data, num_features = label(data > 0, structure=structure)
|
121 |
+
labeled_data_resampled, num_features = label(resampled_data > 0, structure=structure)
|
122 |
else:
|
123 |
labeled_data = resampled_data
|
124 |
num_features = None # Not needed if we're not labeling
|
125 |
|
126 |
# Compute or reuse the center of mass
|
127 |
if center is None:
|
128 |
+
com = center_of_mass(labeled_data_resampled > 0)
|
129 |
center = np.round(com).astype(int)
|
130 |
|
131 |
# Define half the slice size
|
|
|
152 |
return padded_slice
|
153 |
|
154 |
# Extract slices
|
155 |
+
axial_slice = extract_2d_slice(labeled_data_resampled, center, axis=2)
|
156 |
+
coronal_slice = extract_2d_slice(labeled_data_resampled, center, axis=1)
|
157 |
+
sagittal_slice = extract_2d_slice(labeled_data_resampled, center, axis=0)
|
158 |
|
159 |
# Apply rotations
|
160 |
axial_slice = np.rot90(axial_slice, k=-1)
|