def simple_resize(self, path, x_size, y_size):
"""
simply resize image and return array
:param path:
:return:
"""
im = Image.open(path).convert('L')
width = float(im.size[0])
height = float(im.size[1])
newImage = Image.new('L', (x_size, y_size), (255))
if width > height:
nheight = int(round((x_size / width * height), 0))
img = im.resize((x_size, nheight), Image.ANTIALIAS).filter(ImageFilter.SHARPEN)
wtop = int(round(((y_size - nheight) / 2), 0))
newImage.paste(img, (4, wtop))
else:
nwidth = int(round((x_size / height * width), 0))
if (nwidth == 0):
nwidth = 1
img = im.resize((nwidth, y_size), Image.ANTIALIAS).filter(ImageFilter.SHARPEN)
wleft = int(round(((y_size - nwidth) / 2), 0))
newImage.paste(img, (wleft, 4))
return list(newImage.getdata())
test_image_predict_process.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录