preprocess_images.py 文件源码

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

项目:Kaggle-Cat-vs-Dog-Tensorflow-CNN 作者: jshin49 项目源码 文件源码
def process_image(img, img_size, pixel_depth):
    '''
        Maintain aspect ratio of image while resizing
    '''
    img = cv2.imread(img, cv2.IMREAD_COLOR)
    if (img.shape[0] >= img.shape[1]):  # height is greater than width
        resizeto = (img_size, int(
            round(img_size * (float(img.shape[1]) / img.shape[0]))))
    else:
        resizeto = (
            int(round(img_size * (float(img.shape[0]) / img.shape[1]))), img_size)

    img = cv2.resize(img, (resizeto[1], resizeto[
        0]), interpolation=cv2.INTER_CUBIC)
    img = cv2.copyMakeBorder(
        img, 0, img_size - img.shape[0], 0, img_size - img.shape[1], cv2.BORDER_CONSTANT, 0)

    img = normalize_image(img, pixel_depth)

    return img[:, :, ::-1]  # turn into rgb format
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号