OpenCV-颜色反转算法
导读
- 灰度图像颜色反转
- 彩色图像颜色反转
1. 灰度图像颜色反转
import cv2
import numpy as np
img = cv2.imread("../01_Img/01.jpg", 1)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgInfo = img.shape
dst = np.zeros((imgInfo[0], imgInfo[1], 1), np.uint8)
for i in range(0, imgInfo[0]):
for j in range(0, imgInfo[1]):
dst[i, j] = 255-imgGray[i, j]
cv2.imshow("", dst)
cv2.waitKey(0)
2. 彩色图像颜色反转
import cv2
import numpy as np
img = cv2.imread("../01_Img/01.jpg", 1)
imgInfo = img.shape
dst = np.zeros((imgInfo[0], imgInfo[1], 3), np.uint8)
for i in range(0, imgInfo[0]):
for j in range(0, imgInfo[1]):
dst[i, j] = 255-img[i, j]
cv2.imshow("", dst)
cv2.waitKey(0)
https://www.panzer-jack.cn/2022/06/01/OpenCV-%E9%A2%9C%E8%89%B2%E5%8F%8D%E8%BD%AC%E7%AE%97%E6%B3%95/
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Panzer_Jack の 博客!
评论