This warning:Lossy conversion from float64 to uint8. Range [0, 1].
Lossy conversion from float64 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning.
·
在图像预处理/图片处理的过程中,会带有把uint8图像转换成float64类型的警告提示:Lossy conversion from float64 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning.
这时只要添加一行代码即可:
dst = (dst*255.0).astype('uint8')
整体代码如下:
from skimage import io, transform, color
import numpy as np
def convert_gray(f, **args): # 图片处理与格式化的函数
rgb = io.imread(f) # 读取图片
gray = color.rgb2gray(rgb) # 将彩色图片转换为灰度图片
dst = transform.resize(gray, output_shape=(1024, 1024)) # 调整大小,图像分辨率的大小
dst = (dst*255.0).astype('uint8') #保存为uint8类型
return dst
datapath = '/Users/yym/Desktop/n/' # 图片所在的路径
str = datapath + '/*.jpg' # 识别.jpg的图像
coll = io.ImageCollection(str, load_func=convert_gray) # 批处理
for i in range(len(coll)):
io.imsave(r'/Users/yym/Desktop/ui/' + np.str(i) + '.jpg', coll[i])# 保存图片在
更多推荐
已为社区贡献1条内容
所有评论(0)