Skip to content

Commit

Permalink
add resize image w/u aspect ratio function
Browse files Browse the repository at this point in the history
  • Loading branch information
sthanhng committed Oct 17, 2018
1 parent b0c04e7 commit 830f4e7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions yolo/utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 830f4e7

Please sign in to comment.