R语言 把颜色从RGB转换成HSV – rgb2hsv()函数
R语言中的 rgb2hsv() 函数用于将颜色从RGB空间(红/绿/蓝)转换成HSV空间(色调/饱和度/值)。
语法: rgb2hsv(r, g, b)
参数:
r: “红色 “值的向量。
g: “绿色 “值的向量,或者当r是一个矩阵时为空。
b: “蓝色 “值的向量,或者当r是一个矩阵时为空。
例子1 :
# R program to illustrate
# rgb2hsv function
# Calling the col2rgb() function to
# get color in rgb
rgb = col2rgb("# 08a0ff")
# Calling the rgb2hsv() function to
# convert the RGB values in the
# colormap to HSV
rgb2hsv(rgb)
输出
[, 1]
h 0.5641026
s 0.9686275
v 1.0000000
例2 :
# R program to illustrate
# rgb2hsv function
# Calling the rgb2hsv() function
rgb2hsv(60, 120, 180)
输出
[, 1]
h 0.5833333
s 0.6666667
v 0.7058824