diff --git a/yolo/utils.py b/yolo/utils.py new file mode 100644 index 0000000..0915d17 --- /dev/null +++ b/yolo/utils.py @@ -0,0 +1,16 @@ +from PIL import Image + + +def letterbox_image(image, size): + '''Resize image with unchanged aspect ratio using padding''' + + img_width, img_height = image.size + w, h = size + scale = min(w / img_width, h / img_height) + nw = int(img_width * scale) + nh = int(img_height * scale) + + image = image.resize((nw, nh), Image.BICUBIC) + new_image = Image.new('RGB', size, (128, 128, 128)) + new_image.paste(image, ((w - nw) // 2, (h - nh) // 2)) + return new_image