plt.figure()
plt.subplot(1, 2, 1)
plt.imshow(dataset[random_idx][2], cmap='coolwarm')
plt.title("Noisy image")
plt.subplot(1, 2, 2)
plt.imshow(dataset[random_idx][5], cmap='coolwarm')
plt.title("Original image")

np.random.shuffle(dataset)

# Groundtruth: original clean image without edges
groundtruth = [(dataset[ix][0], dataset[ix][1], cut_edges_output(dataset[ix][2]), dataset[ix][3], dataset[ix][4],
                cut_edges_output(dataset[ix][5])) for ix in range(len(dataset))]

# Input: downsampled groundtruth (antialiased)
downsampled = [(dataset[i][0], dataset[i][1], downsample2(groundtruth[i][2], 2), dataset[i][3], dataset[i][4],
                groundtruth[i][5]) for i in range(len(dataset))]

# Reshaping of images
groundtruth = np.array(groundtruth)
downsampled = np.array(downsampled)

groundtruth_img = np.array([groundtruth_item[5].reshape(6, 10, 1) for groundtruth_item in groundtruth])
downsampled_img = np.array([downsampled_item[2].reshape(3, 5, 1) for downsampled_item in downsampled])

# Interpolation with tensorflow
interpolated_tens = tf.image.resize_images(downsampled_img, size=[6, 10], method=ResizeMethod.BICUBIC)
# It is a tensor: turn it into np.array:
tf.InteractiveSession()
interpolated_tf = interpolated_tens.eval()
示例#2
0
print("Length noisy dataset with modes removed: ", str(len(dataset_train)))
print("Length noisy dataset of remaining modes (test): ",
      str(len(dataset_test)))

np.random.shuffle(dataset_train)
np.random.shuffle(dataset_test)

# Groundtruth: original clean image without edges
groundtruth_t = [(dataset_train[ix][0], dataset_train[ix][1],
                  cut_edges_output(dataset_train[ix][2]), dataset_train[ix][3],
                  dataset_train[ix][4], cut_edges_output(dataset_train[ix][5]))
                 for ix in range(len(dataset_train))]

# Input: downsampled groundtruth (antialiased)
downsampled_t = [(dataset_train[i][0], dataset_train[i][1],
                  downsample2(groundtruth_t[i][2], 2), dataset_train[i][3],
                  dataset_train[i][4], groundtruth_t[i][5])
                 for i in range(len(dataset_train))]

# Test sets
groundtruth_test = [(dataset_test[ix][0], dataset_test[ix][1],
                     cut_edges_output(dataset_test[ix][2]),
                     dataset_test[ix][3], dataset_test[ix][4],
                     cut_edges_output(dataset_test[ix][5]))
                    for ix in range(len(dataset_test))]

# Input: downsampled groundtruth (antialiased)
downsampled_test = [(dataset_test[i][0], dataset_test[i][1],
                     downsample2(groundtruth_test[i][2],
                                 2), dataset_test[i][3], dataset_test[i][4],
                     groundtruth_test[i][5]) for i in range(len(dataset_test))]