0

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

enter image description here

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?

Muhamad Iqbal
  • 742
  • 1
  • 4
  • 17
  • I'm not sure I understand your question. matplotlib plots the image using a colormap where the highest value in your data is mapped to black and the lowest value to white and intermediate values correspond to shades of grey. Therefore it does not matter whether your range is [0-1] or [0-255] – Diziet Asahi Sep 10 '19 at 12:13
  • @DizietAsahi is the mapping depends on data or data type? I found from https://stackoverflow.com/questions/49643907/clipping-input-data-to-the-valid-range-for-imshow-with-rgb-data-0-1-for-floa they have valid range for specific datatype – Muhamad Iqbal Sep 11 '19 at 08:25

0 Answers0