create_dataset.py 文件源码

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

项目:MachineLearning 作者: timomernick 项目源码 文件源码
def augment_image(image, augmentation_idx):
    image_height = image.shape[0]
    image_width = image.shape[1]

    if (image_width > hr_size):
        cropX = np.random.randint(0, image_width - hr_size)
    else:
        cropX = 0

    if (image_height > hr_size):
        cropY = np.random.randint(0, image_height - hr_size)
    else:
        cropY = 0

    hr_image = image[cropY:cropY+hr_size,cropX:cropX+hr_size,...]

    lr_image = scipy.misc.imresize(hr_image, [lr_size, lr_size], interp="bilinear")

    # scale low res back to high res so we can learn something other than scaling up the input
    lr_scaled = scipy.misc.imresize(lr_image, [hr_size, hr_size], interp="bilinear")

    # resizing changes to int, go back to float
    lr_image = skimage.img_as_float(lr_image)
    lr_scaled = skimage.img_as_float(lr_scaled)

    #scipy.misc.imsave("hr_" + str(augmentation_idx).zfill(5) + ".png", hr_image)
    #scipy.misc.imsave("hr_" + str(augmentation_idx).zfill(5) + "_small_.png", lr_image)
    #scipy.misc.imsave("hr_" + str(augmentation_idx).zfill(5) + "_scaled_.png", lr_scaled)    

    lr_image = np.swapaxes(lr_image, 0, 2)
    lr_image = np.swapaxes(lr_image, 1, 2)

    hr_image = np.swapaxes(hr_image, 0, 2)
    hr_image = np.swapaxes(hr_image, 1, 2)

    lr_scaled = np.swapaxes(lr_scaled, 0, 2)
    lr_scaled = np.swapaxes(lr_scaled, 1, 2)

    return lr_image, lr_scaled, hr_image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号