python-opencv操作像素进行反色处理

主要内容
“反色处理”指用色彩值的最高值255减去原先的色彩值。本文利用opencv库对图片进行反色处理

主要代码

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)

src1 = cv.imread("yanye.jpg")
src = cv.resize(src1,(600,450),)
cv.imshow('OriginalImage', src)

t1 = cv.getTickCount()
access_pixels(src)
t2 = cv.getTickCount()

print("time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
cv.waitKey()

运行结果
python-opencv操作像素进行反色处理_第1张图片
python-opencv操作像素进行反色处理_第2张图片
参考内容
Python-OpenCV之操作像素进行反色(反相)处理

你可能感兴趣的:(study)