My picture after using tf.image.resize_images becomes a terrible picture

  • original_picture (size: 128 * 128):

enter image description here

  1. after using this function

    image = tf.image.resize_images(original_image,(128,128)) 
  2. Finally, I use plt.imshow () to show my hand image

enter image description here

+5
source share
2 answers

The colors are inverted, that is, each pixel color [r, g, b] displayed as [255 - r, 255 - g, 255 - b] .

This may have something to do with the type of image data you get in step 2. After resizing the image, do the following:

 image = image.astype(np.uint8) 
+1
source

The problem arises from the resize_images function of the tensorflow resize_images function .

To resize and view the image correctly, you will need something like:

 import tensorflow as tf import matplotlib.pyplot as plt import numpy as np with tf.Session() as sess: tf.global_variables_initializer().run() image = tf.image.resize_images(original_image,(128,128)) # Cast image to np.uint8 so it can be properly viewed # eval() tensor to get numpy array. image = tf.cast(image, np.uint8).eval() plt.imshow(image) 
0
source

Source: https://habr.com/ru/post/1271790/


All Articles