版权声明:转载请说明来源,谢谢 https://blog.csdn.net/wsp_1138886114/article/details/82889889
一、遍历访问图片每个像素点,并修改相应的RGB
def access_pixels(image):
print(image.shape)
height = image.shape[0]
width = image.shape[1]
channels = image.shape[2]
print("width: %s height: %s channels: %s"%(width, height, channels))
for row in range(height):
for col in range(width):
for c in range(channels):
pv = image[row , col, c] #获取每个像素点的每个通道的数值
image[row, col, c]=255 - pv #灰度值是0-255 这里是修改每个像素点每个通道灰度值
cv2.imshow("Reverse_phase_image",image)
if __name__ =="__main__":
src=cv2.imread('555.png') #默认彩色读入
cv2.imshow('original_image', src) #显示图像
t1 = cv2.getTickCount() #GetTickcount函数返回从操作系统启动到当前所经过的毫秒数
access_pixels(src)
t2 = cv2.getTickCount()
time = (t2-t1)/cv2.getTickFrequency() #getTickFrequency函数返回CPU的频率,就是每秒的计时周期数
print("time : %s ms"%(time*1000) ) #输出运行时间
cv2.waitKey(0)
cv2.destroyAllWindows()