Skip to content

Commit

Permalink
fix(resampling): Corrected the label centering.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias committed Aug 15, 2023
1 parent cb69914 commit b1994f4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pyradise/process/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,17 @@ def _get_label_center(images: Optional[Sequence[SegmentationImage]]) -> np.ndarr
for label_idx in label_ids:
bounds = filter_.GetBoundingBox(label_idx)
physical_bound_0 = image_sitk.TransformIndexToPhysicalPoint(bounds[0:num_dims])
physical_bound_1 = image_sitk.TransformIndexToPhysicalPoint(bounds[num_dims : 2 * num_dims])
bounding_box.append([physical_bound_0, physical_bound_1])
bounds2 = tuple([
int(x) for x in np.array(bounds[0:num_dims]) + np.array(bounds[num_dims: 2 * num_dims])
])
physical_bound_1 = image_sitk.TransformIndexToPhysicalPoint(bounds2)
bounding_box.append(physical_bound_0)
bounding_box.append(physical_bound_1)

bounding_box = np.array(bounding_box)
label_centers = (bounding_box[:, 0, :] + bounding_box[:, 1, :]) / 2
label_center = np.mean(label_centers, axis=0)
extreme_pt_0 = np.min(bounding_box, axis=0)
extreme_pt_1 = np.max(bounding_box, axis=0)
label_center = (extreme_pt_0 + extreme_pt_1) / 2

return label_center

Expand Down

0 comments on commit b1994f4

Please sign in to comment.