From 79ac3ac9eadf26dafc988407541d8698b607dbe6 Mon Sep 17 00:00:00 2001 From: Yehuda Warszawer <36595323+yw7@users.noreply.github.com> Date: Sat, 7 Dec 2024 01:05:41 +0200 Subject: [PATCH 1/2] Fix value error with 4D images 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). --- totalspineseg/utils/transform_seg2image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/totalspineseg/utils/transform_seg2image.py b/totalspineseg/utils/transform_seg2image.py index 7914cd3..f89756d 100644 --- a/totalspineseg/utils/transform_seg2image.py +++ b/totalspineseg/utils/transform_seg2image.py @@ -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) @@ -307,4 +311,4 @@ def transform_seg2image( return output_seg if __name__ == '__main__': - main() \ No newline at end of file + main() From a0e0251a8e9ef653a017bf413b564a8c4e104f25 Mon Sep 17 00:00:00 2001 From: Yehuda Warszawer <36595323+yw7@users.noreply.github.com> Date: Sat, 7 Dec 2024 19:44:26 +0200 Subject: [PATCH 2/2] Add check for 4D images in `transform_seg2image` function * Check if the input image is 4D and take the first image from the last axis for resampling * Add a comment explaining the purpose of the check for 4D images --- totalspineseg/utils/transform_seg2image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/totalspineseg/utils/transform_seg2image.py b/totalspineseg/utils/transform_seg2image.py index f89756d..dbf782d 100644 --- a/totalspineseg/utils/transform_seg2image.py +++ b/totalspineseg/utils/transform_seg2image.py @@ -311,4 +311,4 @@ def transform_seg2image( return output_seg if __name__ == '__main__': - main() + main() \ No newline at end of file