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

Viewed 2077
  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

3 Answers

I will be using tensorflow library as tf. tf.image.resize resizes the images(correctly) and then when we use plt.imshow on it . But plt.imshow if it sees a float value be it .5 or 221.3 it clips that into the range[0,1].


Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).


This was the problem in my case ,

Original Image pixels[ 91 105 166] .

After resizing tf.Tensor([ 91.01 105.01 166.01], shape=(3,), dtype=float32)

You can see that the resizing is correct but the clipping is the one hurting .

To use the function properly .

img_resize = tf.image.resize(random_img,[250,250])
img_resize = tf.cast(img_resize,'int64')
plt.imshow(img_resize)

This should take care of the issues .

Related