Reputation: 1661
my original image is 600*600 px I want to resize it to be 300*300 px
Resize code
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing.image import array_to_img
from tensorflow_core.python.keras.layers.image_preprocessing import ResizeMethod
def resize(image, w=300, h=300):
image = tf.convert_to_tensor(np.asarray(image))
size = (w, h)
tf.image.resize_with_pad(
image,
h,
w,
method=ResizeMethod.BILINEAR
)
image = array_to_img(image)
return image
After I save the image the dimensions do not change
Save images code
def write_images(images, path):
try:
index = 1
for img in images:
img.save(path+f'/{index}.jpeg')
index += 1
except:
print('Error while writing images')
Upvotes: 0
Views: 1584
Reputation: 3764
Tensorflow operations are not in place. You need to assign the result of the resize operation as follows:
image = tf.image.resize_with_pad(
image,
h,
w,
method=ResizeMethod.BILINEAR
)
Upvotes: 2