From 1de5e2121c1a670b7cf1019809aa60cfc4a0e6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20P=C3=A9rez=20de=20Frutos?= <30429725+jpdefrutos@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:18:45 +0200 Subject: [PATCH] Handling the case in which 2D images extracted from 3D data still hold the 3D spacing in their metadata. The spacing information will be cropped to match the image shape. Added additional test to capture when image_size and spacing do not match --- exporters/spline_segmentation_exporter.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/exporters/spline_segmentation_exporter.py b/exporters/spline_segmentation_exporter.py index 30f76d8..9f60afd 100644 --- a/exporters/spline_segmentation_exporter.py +++ b/exporters/spline_segmentation_exporter.py @@ -247,6 +247,16 @@ def draw_segmentation(image_size, control_points, label: int = 1, canvas: np.nda @staticmethod def compute_scaling(image_size, spacing): + if len(spacing) > len(image_size): + warnings.warn(f'Image is {len(image_size)}D and spacing is {len(spacing)}D.' + f'Dropping the extra axes in the spacing vector.') + for n in range(len(spacing) - len(image_size)): + spacing.pop(-1) + elif len(spacing) < len(image_size): + raise ValueError(f'Something wrong with the data:' + f'image is {len(image_size)}D and spacing is {len(spacing)}D.') + + assert len(image_size) == len(spacing), 'Image size and spacing are expected to have the same dimensions.' if len(spacing) == 2: aspect_ratio = image_size[0] / image_size[1] new_aspect_ratio = image_size[0] * spacing[0] / (image_size[1] * spacing[1])