doc
doc

Reputation: 898

Image resize in tensorflow?

(1300, 730) (433, 320) (428, 320) (428, 320) (108, 108) (416, 301) (42, 42) (307, 307) (34, 34) (1253, 1880) (260, 194) (428, 320) (436, 322) (1253, 1880) (428, 320) (285, 236) (1253, 1880) (259, 194) If I have images with the above mentioned dimensions then how can I resize them to 100 img size. I have tried using tf.image.resize but it takes image tensor of 3D or 4D. How can I resize them.

Upvotes: 0

Views: 1118

Answers (1)

Nicolas Gervais
Nicolas Gervais

Reputation: 36714

You will need to add a channel and batch dimension.

Let's make a random 2D image:

import tensorflow as tf

image = tf.random.uniform(shape=(40, 40), minval=0, maxval=256)

Let's turn this into 4D by adding the two dimensions I mentioned:

three_d_image = tf.expand_dims(image, axis=-1)
four_d_image = tf.expand_dims(three_d_image, axis=0)

Your image now has 4 dimensions:

four_d_image.shape
TensorShape([1, 40, 40, 1])

Now you can reshape it and verify its shape:

tf.image.resize(four_d_image, size=(100, 100)).shape
TensorShape([1, 100, 100, 1])

Upvotes: 1

Related Questions