Based on this solution, you can do the following to pad an image on the right and bottom with zeros:
shape=(200,200)
new_images = [np.zeros(shape) for _ in range(len(images))]
for i,image in enumerate(images):
new_images[i][:image.shape[0], :image.shape[1]] = image
Example:
For a minimal example, padding a set of small images to shape (5,5)
:
# Create random small images
images=[np.random.randn(2,3), np.random.randn(3,3), np.random.randn(5,5)]
# Print out the shape of each image just to demonstrate
>>> [image.shape for image in images]
[(2, 3), (3, 3), (5, 5)]
# Print out first image just to demonstrate
>>> images[0]
array([[-0.49739434, 1.06979644, -0.52647292],
[ 1.21681931, -0.96205689, 0.050574 ]])
# Set your desired shape
shape=(5,5)
# Create array of zeros of your desired shape
new_images = [np.zeros(shape) for _ in range(len(images))]
# loop through and put in your original image values in the beginning
for i,image in enumerate(images):
new_images[i][:image.shape[0], :image.shape[1]] = image
# print out new image shapes to demonstrate
>>> [image.shape for image in new_images]
[(5, 5), (5, 5), (5, 5)]
# print out first image of new_images to demonstrate:
>>> new_images[0]
array([[-0.49739434, 1.06979644, -0.52647292, 0. , 0. ],
[ 1.21681931, -0.96205689, 0.050574 , 0. , 0. ],
[ 0. , 0. , 0. , 0. , 0. ],
[ 0. , 0. , 0. , 0. , 0. ],
[ 0. , 0. , 0. , 0. , 0. ]])