Skip to content

Commit 8a5c313

Browse files
committed
Fix and improve the interpolation logic 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. We changed it so 'area' is used only when the image shrinks a lot (to half its size or smaller). This is because 'area' works best for making images much smaller. For other cases, 'lanczos' is used instead.
1 parent ede3470 commit 8a5c313

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 * 2 and height >= resized_height * 2:
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)