python rgb 图像
Complementary image is a transformed image such that it consists of complementary colours of the ones, which is present in the original image.
互补图像是一种变换后的图像 ,它由原始图像中存在的互补色组成。
For finding the complement of an image, we have to simply subtract each pixel value from the maximum pixel value supported by the class. (in this case, class - uint8, the maximum value of pixel can be 255) and store in the output image array. In the output image, dark areas become lighter and light areas become darker.
为了找到图像的补码 ,我们必须简单地从类支持的最大像素值中减去每个像素值。 (在这种情况下,类为uint8,pixel的最大值可以为255 )并存储在输出图像数组中。 在输出图像中,黑暗区域变亮,明亮区域变暗。
Complementary image = 255 – original image.
补充图像= 255-原始图像 。
In this program, we will be using two functions of OpenCV-python (cv2) module. let's see their syntax and descriptions first :
在此程序中,我们将使用OpenCV-python(cv2)模块的两个功能。 我们先来看一下它们的语法和描述:
1) imread():
It takes an absolute path/relative path of your image file as an argument and returns its corresponding image matrix.
1)imread():
它以图像文件的绝对路径/相对路径作为参数,并返回其对应的图像矩阵。
2) imshow():
It takes window name and image matrix as an argument in order to display an image in a display window with a specified window name.
2)imshow():
它以窗口名称和图像矩阵为参数,以便在具有指定窗口名称的显示窗口中显示图像。
Python程序查找RGB图像的互补图像 (Python program to find complementary image of the RGB image)
# open-cv library is installed as cv2 in python
# import cv2 library into this program
import cv2
# read an image using imread() function of cv2
# we have to pass only the path of the image
img = cv2.imread(r'C:/Users/user/Desktop/pic1.jpg')
# displaying the image using imshow() function of cv2
# In this : 1st argument is name of the frame
# 2nd argument is the image matrix
cv2.imshow('original image',img)
# Find complements of img array and
# store it in the variable
comp_image = 255 - img
# Show the image formed
cv2.imshow("Complementary image",comp_image);
Output
输出量
翻译自: https://www.includehelp.com/python/find-complementary-image-of-the-rgb-image.aspx
python rgb 图像