AnHSVis another type of color space in whichH stands for Hue,S stands for SaturationandV stands for Value.
HSV是另一种颜色空间,其中H代表色相,S代表饱和度,V代表Value。
AHuerepresents color. It is an angle from 0 degrees to 360 degrees.
色相代表颜色。 从0度到360度的角度。
Saturation:It indicates the range of grey in the color space. It ranges from 0 to 100%. Sometimes the value is calculated from 0 to 1. When the value is'0,'the color is grey and when the value is'1,'the color is a primary color.
饱和度:它指示颜色空间中的灰色范围。 范围是0到100%。 有时,该值是从0到1计算的。当值为“ 0”时,颜色为灰色;当值为“ 1”时,颜色为原色。
Valueis the brightness of the color and varies with color saturation. It ranges from 0 to 100%. When the value is'0'the color space will be totally black. With the increase in the value, the color space brightness up and shows various colors.
值是颜色的亮度,并随颜色饱和度而变化。 范围是0到100%。 当值为“ 0”时,颜色空间将完全为黑色。 随着该值的增加,色彩空间的亮度会提高并显示各种颜色。
In this program, we will be using three 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():
它以窗口名称和图像矩阵为参数,以便在具有指定窗口名称的显示窗口中显示图像。
3) cv2.cvtColor():
It takes image matrix and a flag for changing color-space from one color space to another(in this case we are using BGR2HSVcolor-space conversion) and returns the newly converted image matrix.
3)cv2.cvtColor():
它需要图像矩阵和用于将颜色空间从一种颜色空间更改为另一种颜色的标志(在这种情况下,我们使用BGR2HSV颜色空间转换),并返回新转换的图像矩阵。
Python程序将RGB格式的图像转换为HSV格式的图像 (Python program to convert an RGB format Image in an HSV format Image)
# open-cv library is installed as cv2 in python# import cv2 library into this programimport cv2# read an image using imread() function of cv2# we have to pass only the path of the imageimg = 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 matrixcv2.imshow('original image',img)# converting the colourfull image into HSV format image# using cv2.COLOR_BGR2HSV argument of# the cvtColor() function of cv2# in this :# ist argument is the image matrix# 2nd argument is the attributeHSV_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)# displaying the Hsv format imagecv2.imshow('HSV format image',HSV_img)
Output
输出量
翻译自: /python/convert-an-rgb-format-image-in-an-hsv-format-image-using-opencv.aspx
如果觉得《在Python中使用OpenCV将RGB格式的图像转换为HSV格式的图像》对你有帮助,请点赞、收藏,并留下你的观点哦!