Skip to content

Commit 606e687

Browse files
authored
Merge pull request #2022 from LexSong/fix-resize-issue
Fix size parameter types and improve resize_image interpolation
2 parents 92845e8 + b822b7e commit 606e687

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

library/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,19 @@ def resize_image(image: np.ndarray, width: int, height: int, resized_width: int,
413413
Returns:
414414
image
415415
"""
416+
417+
# Ensure all size parameters are actual integers
418+
width = int(width)
419+
height = int(height)
420+
resized_width = int(resized_width)
421+
resized_height = int(resized_height)
422+
416423
if resize_interpolation is None:
417-
resize_interpolation = "lanczos" if width > resized_width and height > resized_height else "area"
418-
424+
if width >= resized_width and height >= resized_height:
425+
resize_interpolation = "area"
426+
else:
427+
resize_interpolation = "lanczos"
428+
419429
# we use PIL for lanczos (for backward compatibility) and box, cv2 for others
420430
use_pil = resize_interpolation in ["lanczos", "lanczos4", "box"]
421431

0 commit comments

Comments
 (0)