How to convert an image from np.uint16 to np.uint8?

前端 未结 2 1674
慢半拍i
慢半拍i 2020-12-14 17:13

I am creating an image so:

image = np.empty(shape=(height, width, 1), dtype = np.uint16)

After that I convert the image to BGR model:

2条回答
  •  难免孤独
    2020-12-14 17:38

    I suggest you to use this :

    outputImg8U = cv2.convertScaleAbs(inputImg16U, alpha=(255.0/65535.0))
    

    this will output a uint8 image & assign value between 0-255 with respect to there previous value between 0-65535

    exemple :
    pixel with value == 65535 will output with value 255 
    pixel with value == 1300 will output with value 5 etc...
    

提交回复
热议问题