From eed5d21a7eabe5c27512c78b820e28d377d654ed Mon Sep 17 00:00:00 2001 From: Jakub Both Date: Tue, 18 Jun 2024 06:47:49 +0200 Subject: [PATCH] MAINT: Only apply data conversion if needed. --- src/darsia/corrections/shape/curvature.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/darsia/corrections/shape/curvature.py b/src/darsia/corrections/shape/curvature.py index 2d52d73c..4373d544 100644 --- a/src/darsia/corrections/shape/curvature.py +++ b/src/darsia/corrections/shape/curvature.py @@ -779,8 +779,13 @@ def _transform_image( im_array_as_vector = map_coordinates( in_data, grid, order=self.interpolation_order ) - # Convert to correct shape and data type - corrected_img[:, :, i] = im_array_as_vector.reshape(shape).astype(img.dtype) + # Convert to correct shape and data type (if necessary) + if im_array_as_vector.dtype == img.dtype: + corrected_img[:, :, i] = im_array_as_vector.reshape(shape) + else: + corrected_img[:, :, i] = im_array_as_vector.reshape(shape).astype( + img.dtype + ) return np.squeeze(corrected_img)