opencv 将float64转成uint8 (Python)

opencv如何将float64图片类型转成uint8呢(Python),霍夫变换需要八位单通道的,而我现在时float64

img

可以试试用numpy转换

from PIL import Image
from pylab import *
 
im = array(Image.open("test.jpg"))
#unit8
print(im.dtype) 
# 将图像像素值变换到100...200 区间
im3 = 255.0 * (im/255.0)**2 
 #float64
print(im3.dtype)
# 通过PIL中的fromarray方法将图片转换为uint8格式(此时的pil_im为image对象)
pil_im = Image.fromarray(uint8(im3))
imshow(pil_im)
show()

以下方法都可以:
(1) imgUint8 = imgFloat64.astype(np.uint8)
(2) imgUnit8 = np.uint8(imgFloat64)

更多参见:https://blog.csdn.net/youcans/article/details/124181211