import numpy as np
import cv2
im = cv2.imread('tetet.jpg')
im_converted_mat = np.zeros_like(im, dtype=np.uint8)
for x in range(im.shape[0]):
for y in range(im.shape[1]):
# 补色公式max(r,g,b)+min(r,g,b)-[r,g,b]
maxrgb = im[x][y].max()
minrgb = im[x][y].min()
im_converted_mat[x][y] = (int(maxrgb) + int(minrgb)) * np.ones(3) - im[x][y]
# 反色公式[255,255,255]-[r,g,b]
im_converted_mat2 = np.ones_like(im) * 255 - im
cv2.imshow('buse', im_converted_mat)
cv2.imshow('fanse', im_converted_mat2)
cv2.imwrite('buse.jpg', im_converted_mat)
cv2.imwrite('fanse.jpg', im_converted_mat2)
cv2.waitKey()
原图
补色
反色