Convert RGB to black OR white

后端 未结 8 1134
我在风中等你
我在风中等你 2020-11-30 23:20

How would I take an RGB image in Python and convert it to black OR white? Not grayscale, I want each pixel to be either fully black (0, 0, 0) or fully white (255, 255, 255).

8条回答
  •  渐次进展
    2020-11-30 23:27

    img_rgb = cv2.imread('image.jpg')
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    (threshi, img_bw) = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
    

提交回复
热议问题