From 619e88226afebd0c1aed060919861e4b32705525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9lodie?= <melo.boillet@gmail.com> Date: Wed, 26 Jul 2023 08:48:32 +0200 Subject: [PATCH] Fix padding to bottom-right --- dan/utils.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/dan/utils.py b/dan/utils.py index 6ceede28..995465a7 100644 --- a/dan/utils.py +++ b/dan/utils.py @@ -24,27 +24,23 @@ def pad_sequences_1D(data, padding_value): return padded_data -def pad_images(data): +def pad_images(images): """ - Pad the images so that they are in the middle of the large padded image (tb-lr mode). - :param data: List of numpy arrays. - :return padded_data: A tensor containing all the padded images. + Pad the images so that they are at the top left of the large padded image. + :param images: List of images as torch tensors. + :return padded_images: A tensor containing all the padded images. """ - longest_x = max([x.shape[0] for x in data]) - longest_y = max([x.shape[1] for x in data]) - padded_data = np.zeros((len(data), longest_x, longest_y, data[0].shape[2])) - for index, image in enumerate(data): - delta_x = longest_x - image.shape[0] - delta_y = longest_y - image.shape[1] - top, bottom = delta_x // 2, delta_x - (delta_x // 2) - left, right = delta_y // 2, delta_y - (delta_y // 2) - padded_data[ + longest_x = max([x.shape[0] for x in images]) + longest_y = max([x.shape[1] for x in images]) + padded_images = np.zeros((len(images), longest_x, longest_y, images[0].shape[2])) + for index, image in enumerate(images): + padded_images[ index, - top : padded_data.shape[1] - bottom, - left : padded_data.shape[2] - right, + 0 : image.shape[0], + 0 : image.shape[1], :, ] = image - return padded_data + return padded_images def read_image(filename, scale=1.0): -- GitLab