21_颜色反转

#灰度图片的颜色反转
#0-255  ,255-当前灰度值
import cv2
import numpy as np
img = cv2.imread('ruonan.jpg',1)
Info = img.shape
height = Info[0]
width = Info[1]
dst = np.zeros((height,width,1),np.uint8)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
for i in range(0,height):
 for j in range(0,width):
  grayPixel = gray[i,j]
  dst[i,j] = 255-grayPixel
cv2.imshow('dstImg',dst)
#彩色图片的颜色反转
#0-255  ,255-当前灰度值
import cv2
import numpy as np
img = cv2.imread('ruonan.jpg',1)
Info = img.shape
height = Info[0]
width = Info[1]
dst = np.zeros((height,width,3),np.uint8)
#gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
for i in range(0,height):
 for j in range(0,width):
  (b,g,r) = img[i,j]
  dst[i,j] = (255-b,255-g,255-r)
cv2.imshow('dstImg',dst)
cv2.waitKey(0)
上一篇:buuctf reverse3


下一篇:22_边缘检测