我正在创建一个图像,所以:
image = np.empty(shape=(height, width, 1), dtype = np.uint16)
之后,我将图像转换为BGR模型:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
为了通过cv2.threshold()
函数使用该图像,我想现在将图像转换为dtype = np.uint8
。我的意思是,我想要将图像转换为CV_8UC1
。
发布于 2012-07-05 23:04:45
你可以使用cv2.convertScaleAbs
来解决这个问题。请参阅Documentation.
查看下面的命令终端演示:
>>> img = np.empty((100,100,1),dtype = np.uint16)
>>> image = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
>>> cvuint8 = cv2.convertScaleAbs(image)
>>> cvuint8.dtype
dtype('uint8')
希望它能有所帮助!
发布于 2014-02-14 19:35:19
我建议你使用这个:
outputImg8U = cv2.convertScaleAbs(inputImg16U, alpha=(255.0/65535.0))
这将输出一个uint8图像,并将0-65535之间的值分配给之前的值
exemple :
pixel with value == 65535 will output with value 255
pixel with value == 1300 will output with value 5 etc...
https://stackoverflow.com/questions/11337499
复制相似问题