From 75453a5ce3413611e5d2a32c687c33005c156446 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Tue, 19 Mar 2024 20:56:46 +0100 Subject: [PATCH] Refactor --- tools/scale_image/scale_image.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/scale_image/scale_image.py b/tools/scale_image/scale_image.py index 4137653c..47957f5f 100644 --- a/tools/scale_image/scale_image.py +++ b/tools/scale_image/scale_image.py @@ -26,14 +26,10 @@ def scale_image(input_file, output_file, scale, order, antialias): scale = [scale] * (im.ndim - 1) + [1] # Do the scaling - res = skimage.transform.rescale(im, scale, order, anti_aliasing=antialias) + res = skimage.transform.rescale(im, scale, order, anti_aliasing=antialias, preserve_range=True) - # Convert `res` to the same dtype as `im`, - # it is important to preserve the dtype so that both brightness and range of values is preserved + # Preserve the `dtype` so that both brightness and range of values is preserved if res.dtype != im.dtype: - src_max_value = skimage.util.dtype_limits(res)[1] - dst_max_value = skimage.util.dtype_limits(im)[1] - res = (res / src_max_value) * dst_max_value if np.issubdtype(im.dtype, np.integer): res = res.round() res = res.astype(im.dtype)