Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

my picture after using tf.image.resize_images becomes horrible picture

Tags:

tensorflow

  1. original_picture (size:128*128) like this:

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 picture

enter image description here

like image 746
陳清山 Avatar asked Sep 14 '17 11:09

陳清山


People also ask

How do I rescale an image in Tensorflow?

This is achieved by using the "tf. image. resize()" function available in the tensorflow. It will resize the images to the size using the specified method.

What is image resizing in image processing?

Image resizing is necessary when you need to increase or decrease the total number of pixels, whereas remapping can occur when you are correcting for lens distortion or rotating an image. Zooming refers to increase the quantity of pixels, so that when you zoom an image, you will see more detail.

How do I resize an image without cropping in Python?

resize_contain resize the image so that it can fit in the specified area, keeping the ratio and without crop (same behavior as background-size: contain). resize_height resize the image to the specified height adjusting width to keep the ratio the same.

How do I resize an image while maintaining its aspect ratio OpenCV?

To resize an image in Python, you can use cv2. resize() function of OpenCV library cv2. Resizing, by default, does only change the width and height of the image. The aspect ratio can be preserved or not, based on the requirement.


1 Answers

The problem comes from tensorflow's resize_images function returning floats.

To properly resize and view the image you would 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)
like image 57
Karsus Avatar answered Sep 28 '22 20:09

Karsus