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
评论列表
文章目录