内容简介:图像颜色的反转,比较简单的思路就是使用255减去当前值,从而得到反转后的图像。原始图片:原始图片
图像颜色的反转,比较简单的思路就是使用255减去当前值,从而得到反转后的图像。原始图片:
原始图片
1、灰度图像的颜色反转
import cv2
import numpy as np
# 灰度 0-255 255-当前灰度值
img = cv2.imread('linuxidc.com.jpg', 1)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dst = np.zeros((height, width, 1), np.uint8)
for i in range(height):
for j in range(width):
grayPixel = 255 - gray[i, j]
dst[i, j] = grayPixel
cv2.imshow('linuxidc.com', dst)
cv2.waitKey(0)
用255减去当前灰度值,得到反转后的图像。图像如下:
2、BGR图像的反转
import cv2
import numpy as np
img = cv2.imread('linuxidc.com.jpg', 1)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
dst = np.zeros((height, width, 3), np.uint8)
for i in range(height):
for j in range(width):
(b, g, r) = img[i, j]
b = 255 - b
g = 255 - g
r = 255 - r
dst[i, j] = (b, g, r)
cv2.imshow('www.linuxidc.com', dst)
cv2.waitKey(0)
BGR图像反转也是一样,同样是使用255减去每一个通道的当前值。效果如下:
更多 Python 相关信息见 Python 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17
Linux公社的RSS地址 : https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址: https://www.linuxidc.com/Linux/2019-05/158621.htm
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Writing Apache Modules with Perl and C
Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95
Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!