pyplot.imshow如何处理具有不同数据类型的图像?

时间:2019-09-10 09:13:34

标签: python image matplotlib

我目前正在处理GAN模型,并使用matplotlib.pyplot.imshow将图像保存为网格格式。

在保存GAN生成的图像样本期间,我意识到当将其放入float32时,它仍然处于pyplot.imshow数据类型,这与我的初始图像数据格式(uint8)不同。因此,出于研究目的,我将图像投射回值范围为0-255的uint8

当我用pyplot.imshow检查两个图像时,看到的图像非常相似

enter image description here

这就是我绘制所有图像的方式

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()

这如何产生相似的图像图,尤其是当输入具有不同的数据类型时?

0 个答案:

没有答案
相关问题