1 Star 0 Fork 0

秦敏杰/scanpath

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
imutils.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
sunwanjie 提交于 2020-10-20 16:28 . add code
import numpy as np
from PIL import Image
def pad_img_KAR(img, target_w, target_h, pad_value=(124, 116, 104)):
w, h = img.size
if w / h == target_w / target_h:
return img, (0, 0)
if w < h or w * (target_h / target_w) < h:
new_w = int(h * (target_w / target_h))
new_img = Image.new('RGB', (new_w, h), color=pad_value)
new_img.paste(img, (int((new_w - w) // 2), 0))
return new_img, (new_w - w, 0)
else:
new_h = int(w * (target_h / target_w))
new_img = Image.new('RGB', (w, new_h), color=pad_value)
new_img.paste(img, (0, int((new_h - h) // 2)))
return new_img, (0, new_h - h)
def pad_array_KAR(arr, target_h, target_w, pad_value=np.array([[0]])):
h, w = arr.shape
if w / h == target_w / target_h:
return arr, (0, 0)
if w < h or w * (target_h / target_w) < h:
new_w = int(h * (target_w / target_h))
new_arr = np.ones((h, new_w)) * pad_value
new_arr[:, int((new_w - w) // 2):int((new_w - w) // 2)+w] = arr
return new_arr, (0, new_w - w)
else:
new_h = int(w * (target_h / target_w))
new_arr = np.ones((new_h, w)) * pad_value
new_arr[int((new_h - h) // 2):int((new_h - h) // 2) + h, :] = arr
return new_arr, (new_h - h, 0)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qin_minjie/scanpath.git
git@gitee.com:qin_minjie/scanpath.git
qin_minjie
scanpath
scanpath
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385