代码错误。 Scikit 图像,Spyder

Mistake in the code. Scikit-image, Spyder

我收到了这个警告,但我无法修复它。代码有效。

Warning: Lossy conversion from float64 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning.

from skimage.io import imread, imshow, imsave 

img_grey = imread('C:/Lawn.png', as_gray=True)
imsave('Lawn22.png', img_grey)

img = imread('C:/Lawn.png')
imshow(img)

阅读图像后,您需要像下面这样转换 float64 to type uint8 以使用此代码删除此警告消息:

img_grey = img_grey / img_grey.max() #normalizes img_grey in range 0 - 255
img_grey = 255 * img_grey
img_grey = img_grey.astype(np.uint8)

没有警告信息的完整代码:

from skimage.io import imread, imshow, imsave 
img_grey = imread('C:/Lawn.png', as_gray=True)

# convert image to uint8
img_grey = img_grey / img_grey.max() #normalizes img_grey in range 0 - 255
img_grey = 255 * img_grey
img_grey = img_grey.astype(np.uint8)


imsave('Lawn22.png', img_grey)
img = imread('C:/Lawn.png')
imshow(img_grey)