我只是想让我在 python 中使用 scikit-image 加载的给定图像变暗。
如果我这样做:
test_image = io.imread("TestProvs2.bmp")
test_image = test_image * 0.5
show_map(test_image)
RGB 值数组确实按比例缩小,因此每个 RGB 值都是 127.5。
当您读取图像时,图像的数据类型是
uint8
。当你除以 0.5
时,python 将其转换为 float64
但图像必须是 uint8
,所以它给出了这个错误
Lossy conversion from float64 to uint8. Range [0.0, 127.5]. Convert image to uint8 prior to saving to suppress this warning.
你要做的就是手动将其投射到
uint8
。
test_image = (test_image * 0.5).astype(np.uint8)