将图像从float64转换为uint8会使图像看起来像d

2024-09-29 17:21:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我有GANs生成的float64类型的图像,并通过^{}保存它们。该过程运行良好,保存的图像看起来不错,但我收到一条警告消息,如下所示:

Lossy conversion from float64 to uint8. Range [-0.9999998807907104, 0.9999175071716309]. Convert image to uint8 prior to saving to suppress this warning.

然后,在使用函数^{}保存之前,我尝试通过将图像转换为uint8来消除此警告。这给了我一个明显暗得多的警告图像

UserWarning: Possible precision loss when converting from float64 to uint8 .format(dtypeobj_in, dtypeobj_out))

在保存之前,我也尝试过使用其他函数,比如来自tensorflow^{}的函数。它们返回的图像比我直接调用的要暗略读.io.imsave. 有什么问题吗?在

下面是一组在保存之前转换成uint8生成的图像 enter image description here

下面是一组直接保存生成的图像


Tags: to函数from图像消息警告类型过程
2条回答

来自the documentation of ^{} that you linked

Negative input values will be clipped. Positive values are scaled between 0 and 255.

因为你的图像在[-1,1]的范围内,一半的数据将被设置为0,这就是为什么东西看起来更暗。在调用skimage.img_as_ubyte之前,请先尝试将图像缩放到一个仅为正的范围,例如将1添加到其中。在

我用

import numpy as np
import imageio

# suppose that img's dtype is 'float64'
img_uint8 = img.astype(np.uint8)
# and then
imageio.imwrite('filename.jpg', img_uint8)

就这样!在

相关问题 更多 >

    热门问题