Resizing
Use TensorFlow to resize images with a variety of different image scaling algorithms.
We'll cover the following...
Chapter Goals:
- Be able to resize pixel data when required
- Understand how resizing works in TensorFlow
A. Basic resizing
The function we use for resizing pixel data is tf.image.resize
. It takes in two required arguments: the original image's decoded data and the new size of the image, which is a tuple/list of two integers representing new_height
and new_width
, in that order.
Press + to interact
import tensorflow as tfwith tf.compat.v1.Session() as sess:print('Original: {}'.format(repr(sess.run(decoded_image)))) # Decoded image dataresized_img = tf.image.resize(decoded_image, (3, 2))print('Resized: {}'.format(repr(sess.run(resized_img))))
The function compresses or expands the image (depending on the relationship between the new image dimensions and the old image dimensions) and then returns the pixel data for the resized image, with the same number of channels. Note that if the resized dimensions don't match the same aspect ratio as the ...