def extract_patches(filename_base, num_images, patch_size=conf.patch_size, phase='train'):
patches = []
for i in range(1, num_images+1):
if phase == 'train':
imageid = "satImage_%.3d" % i
image_filename = filename_base + imageid + ".png"
if os.path.isfile(image_filename):
img = mpimg.imread(image_filename)
img = resize(img, (conf.train_image_resize, conf.train_image_resize))
patches.append(image.extract_patches(img, (patch_size, patch_size), extraction_step=1))
rot90img = rotate(img, 90, reshape=False, mode='reflect', order=3)
patches.append(image.extract_patches(rot90img, (patch_size, patch_size), extraction_step=1))
rot45img = rotate(img, 45, reshape=False, mode='reflect', order=3)
patches.append(image.extract_patches(rot45img, (patch_size, patch_size), extraction_step=1))
rot135img = rotate(img, 135, reshape=False, mode='reflect', order=3)
patches.append(image.extract_patches(rot135img, (patch_size, patch_size), extraction_step=1))
elif phase == 'test':
imageid = "raw_test_%d_pixels" % i
image_filename = filename_base + imageid + ".png"
if os.path.isfile(image_filename):
img = mpimg.imread(image_filename)
img = resize(img, (conf.test_image_resize, conf.test_image_resize))
patches.append(image.extract_patches(img, (patch_size, patch_size), extraction_step=1))
elif phase == 'train_cnn_output':
imageid = "raw_satImage_%.3d_pixels" % i
image_filename = filename_base + imageid + ".png"
if os.path.isfile(image_filename):
img = mpimg.imread(image_filename)
img = resize(img, (conf.train_image_resize, conf.train_image_resize))
patches.append(image.extract_patches(img, (patch_size, patch_size), extraction_step=1))
else:
raise ValueError('incorrect phase')
return patches
denoise_autoencoder.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录