下面介绍两种采用Python+OpenCV的二值图像取反方法:
【方法一】
import cv2
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
t, imageThresh = cv2.threshold(image , 125, 255, cv.THRESH_BINARY)
inverted_image = 255 - imageThresh
cv2.imshow('Inverted Image', inverted_image)
cv2.waitKey(0)
【方法二】
import cv2
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
t, imageThresh = cv2.threshold(image , 125, 255, cv.THRESH_BINARY)
inverted_image = cv2.bitwise_not(imageThresh)
cv2.imshow('Inverted Image', inverted_image)
cv2.waitKey(0)