From ede34702609c59ba2256cf7e330bad67ce9c77d3 Mon Sep 17 00:00:00 2001 From: Lex Song Date: Wed, 2 Apr 2025 03:28:58 +0800 Subject: [PATCH 1/2] Ensure all size parameters are integers to prevent type errors --- library/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/utils.py b/library/utils.py index 0f535a87..767de472 100644 --- a/library/utils.py +++ b/library/utils.py @@ -413,6 +413,13 @@ def resize_image(image: np.ndarray, width: int, height: int, resized_width: int, Returns: image """ + + # Ensure all size parameters are actual integers + width = int(width) + height = int(height) + resized_width = int(resized_width) + resized_height = int(resized_height) + if resize_interpolation is None: resize_interpolation = "lanczos" if width > resized_width and height > resized_height else "area" From b822b7e60b84a4fb32a8e1ffa966054f8fe96209 Mon Sep 17 00:00:00 2001 From: Lex Song Date: Wed, 2 Apr 2025 03:32:36 +0800 Subject: [PATCH 2/2] Fix the interpolation logic error in resize_image() The original code had a mistake. It used 'lanczos' when the image got smaller (width > resized_width and height > resized_height) and 'area' when it stayed the same or got bigger. This was the wrong way. 'area' is better for big shrinking. --- library/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/utils.py b/library/utils.py index 767de472..d0586b84 100644 --- a/library/utils.py +++ b/library/utils.py @@ -421,8 +421,11 @@ def resize_image(image: np.ndarray, width: int, height: int, resized_width: int, resized_height = int(resized_height) if resize_interpolation is None: - resize_interpolation = "lanczos" if width > resized_width and height > resized_height else "area" - + if width >= resized_width and height >= resized_height: + resize_interpolation = "area" + else: + resize_interpolation = "lanczos" + # we use PIL for lanczos (for backward compatibility) and box, cv2 for others use_pil = resize_interpolation in ["lanczos", "lanczos4", "box"]