Skip to content

Commit b822b7e

Browse files
committed
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.
1 parent ede3470 commit b822b7e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,11 @@ def resize_image(image: np.ndarray, width: int, height: int, resized_width: int,
421421
resized_height = int(resized_height)
422422

423423
if resize_interpolation is None:
424-
resize_interpolation = "lanczos" if width > resized_width and height > resized_height else "area"
425-
424+
if width >= resized_width and height >= resized_height:
425+
resize_interpolation = "area"
426+
else:
427+
resize_interpolation = "lanczos"
428+
426429
# we use PIL for lanczos (for backward compatibility) and box, cv2 for others
427430
use_pil = resize_interpolation in ["lanczos", "lanczos4", "box"]
428431

0 commit comments

Comments
 (0)