np.where
来使白色像素变成红色像素。这是结果:
二进制掩模
结果
import cv2
import numpy as np
# Load image, grayscale, Otsu's threshold
image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY_INV)[1]
# Color pixels red where there are white pixels on the mask
image[np.where(thresh==255)] = [0,0,255]
# Display
cv2.imshow('thresh', thresh)
cv2.imshow('image', image)
cv2.waitKey()