I'm currently working on GAN models and using matplotlib.pyplot.imshow
to save the image in grid format.
During saving image samples generated by GANs, I realized it was still in float32
data type when I put it into pyplot.imshow
, different with my initial image data format (uint8
). So for research purpose, I casted the image back into uint8
with 0-255 value range.
When I inspect both images with pyplot.imshow
, I'm seeing a very similar image
This is how I plot all the images
img = # input image for GAN
gen_img = # GAN output given 'img' as input
fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(12, 16),
subplot_kw={'xticks': [], 'yticks': []})
axs = axs.flat
img = (img + 1) * 127.5
axs[0].imshow(np.reshape(img, (row, col)))
axs[0].set_title('Source')
gen_img_float = gen_img * 0.5 + 0.5
axs[1].imshow(np.reshape(gen_img_float[0], (row, col)))
axs[1].set_title('gen_img shown in [0-1] float scale')
gen_img_uint = (gen_img + 1) * 127.5
axs[2].imshow(np.reshape(gen_img_uint[0].astype('uint8'), (row, col)))
axs[2].set_title('gen_imgs shown in [0-255] uint8 scale')
plt.show()
How does this resulting in similar image plot, especially when the inputs are in different datatypes?