Skip to content

Commit

Permalink
Fix value error with 4D images
Browse files Browse the repository at this point in the history
Fixes #95

Add handling for 4D images in `transform_seg2image` function.

* Add a check for 4D images at the beginning of the `transform_seg2image` function.
* If the input image is 4D, take the first image from the last axis for resampling.
* Add a comment explaining the purpose of the check for 4D images.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/neuropoly/totalspineseg/issues/95?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
yw7 committed Dec 6, 2024
1 parent d3e3157 commit 79ac3ac
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion totalspineseg/utils/transform_seg2image.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ def transform_seg2image(
nibabel.Nifti1Image
Output segmentation.
'''
# Check if the input image is 4D and take the first image from the last axis for resampling
if len(np.asanyarray(image.dataobj).shape) == 4:
image = image.slicer[..., 0]

image_data = np.asanyarray(image.dataobj).astype(np.float64)
image_affine = image.affine.copy()
seg_data = np.asanyarray(seg.dataobj)
Expand Down Expand Up @@ -307,4 +311,4 @@ def transform_seg2image(
return output_seg

if __name__ == '__main__':
main()
main()

0 comments on commit 79ac3ac

Please sign in to comment.