PS里也称反相。就是将像素点的颜色变成与原先相反的颜色,这里的“相反”指的是用色彩值的最高值255减去原先的色彩值。
import cv2 as cv
def access_pixels(image):
height, width, channels = image.shape
print("width:%s,height:%s,channels:%s" % (width, height, channels))
for row in range(height):
for list in range(width):
for c in range(channels):
pv = image[row, list, c]
image[row, list, c] = 255 - pv
cv.imshow("AfterDeal", image)
src = cv.imread('test.jpg')
cv.imshow('OriginalImage', src)
# 获取当前系统以运行的周期数
t1 = cv.getTickCount()
# 运行函数
access_pixels(src)
# 再次获取当前系统以运行的周期数
t2 = cv.getTickCount()
# 计时周期数差值除以每秒周期数,获得处理时间
print("time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
cv.waitKey()