Reputation: 61
I have read a grayscale image and looks normal, but the image looks very strange after converting data type by tf.image.convert_image_dtype(). I don't know what happened, appreciate any help.
... ...
uint_inputs = tf.image.convert_image_dtype(inputs, dtype=tf.uint8, saturate=False)
... ...
with sv.managed_session() as sess:
inputs, uint_inputs = sess.run([inputs, uint_inputs])
f ,axis = plt.subplots(1, 2, figsize=(4, 2))
axis[0].imshow(np.squeeze(inputs), cmap='gray')
axis[1].imshow(np.squeeze(uint_inputs), cmap='gray')
plt.show()
Results after running as follows,
Upvotes: 1
Views: 443
Reputation: 61
After a long struggle, I found the inputs must be in [0, 1) if they are float type in tf.image.convert_image_dtype(inputs, dtype=tf.uint8, saturate=False)
. Thus, I just scale the inputs by inputs = inputs/255
before they are feed into the tf.image.convert_image_dtype
pipline.
Upvotes: 1