image_preprocess.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:tensormsa_old 作者: TensorMSA 项目源码 文件源码
def simple_resize(self, path, x_size, y_size):
        """
        simply resize image and return array
        :param path:
        :return:
        """
        x_size = int(x_size)
        y_size = int(y_size)
        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 newImage.getdata()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号