rgb2hsv(grDevices)
rgb2hsv()所属R语言包:grDevices
RGB to HSV Conversion
RGB到单纯疱疹病毒转换
译者:生物统计家园网 机器人LoveR
描述----------Description----------
rgb2hsv transforms colors from RGB space (red/green/blue) into HSV space (hue/saturation/value).
rgb2hsv变换颜色(红/绿/蓝)从RGB空间到HSV空间(色相/饱和度/价值)。
用法----------Usage----------
rgb2hsv(r, g = NULL, b = NULL, maxColorValue = 255)
参数----------Arguments----------
参数:r
vector of "red" values in [0, M], (M = maxColorValue) or 3-row rgb matrix.
向量红值[0, M](M = maxColorValue)或3行RGB矩阵。
参数:g
vector of "green" values, or NULL when r is a matrix.
“绿色”的价值观,或NULL向量时r是一个矩阵。
参数:b
vector of "blue" values, or NULL when r is a matrix.
向量的“蓝色”的价值观,或NULL时r是一个矩阵。
参数:maxColorValue
number giving the maximum of the RGB color values range. The default 255 corresponds to the typical 0:255 RGB coding as in col2rgb().
数量给予最大的RGB颜色值的范围。默认255对应典型的0:255col2rgb()的RGB编码。
Details
详情----------Details----------
Value (brightness) gives the amount of light in the color.<br> Hue describes the dominant wavelength.<br> Saturation is the amount of Hue mixed into the color.
(亮度)值给出颜色的光量。参考的色相介绍主波长。参考饱和的色调混合成的颜色。
An HSV colorspace is relative to an RGB colorspace, which in R is sRGB, which has an implicit gamma correction.
单纯疱疹病毒的色彩是相对的RGB色彩空间,其中R是sRGB,它有一个隐含的伽玛校正。
值----------Value----------
A matrix with a column for each color. The three rows of the matrix indicate hue, saturation and value and are named "h", "s", and "v" accordingly.
每种颜色的列矩阵。矩阵的三行表示色相,饱和度和价值,被命名为"h","s","v"相应。
作者(S)----------Author(s)----------
<font face="Courier New,Courier" color="#666666"><b>R</b></font> interface by Wolfram Fischer <a href="mailto:wolfram@fischer-zim.ch">wolfram@fischer-zim.ch</a>;<br>
C code mainly by Nicholas Lewin-Koh <a href="mailto:nikko@hailmail.net">nikko@hailmail.net</a>.
参见----------See Also----------
hsv, col2rgb, rgb.
hsv,col2rgb,rgb。
举例----------Examples----------
## These (saturated, bright ones) only differ by hue[#这些(饱和,鲜艳的)仅相差色调]
(rc <- col2rgb(c("red", "yellow","green","cyan", "blue", "magenta")))
(hc <- rgb2hsv(rc))
6 * hc["h",] # the hues are equispaced[有均布的色调]
(rgb3 <- floor(256 * matrix(stats::runif(3*12), 3,12)))
(hsv3 <- rgb2hsv(rgb3))
## Consistency :[#一致性:]
stopifnot(rgb3 == col2rgb(hsv(h=hsv3[1,], s=hsv3[2,], v=hsv3[3,])),
all.equal(hsv3, rgb2hsv(rgb3/255, maxColorValue = 1)))
## A (simplified) pure R version -- originally by Wolfram Fischer --[#(简体)纯R版本 - 最初由Wolfram菲舍尔 - ]
## showing the exact algorithm:[#显示精确算法:]
rgb2hsvR <- function(rgb, gamma = 1, maxColorValue = 255)
{
if(!is.numeric(rgb)) stop("rgb matrix must be numeric")
d <- dim(rgb)
if(d[1] != 3) stop("rgb matrix must have 3 rows")
n <- d[2]
if(n == 0) return(cbind(c(h=1,s=1,v=1))[,0])
rgb <- rgb/maxColorValue
if(gamma != 1) rgb <- rgb ^ (1/gamma)
## get the max and min[#获得最大和最小]
v <- apply( rgb, 2, max)
s <- apply( rgb, 2, min)
D <- v - s # range[范围]
## set hue to zero for undefined values (gray has no hue)[#设置色调未定义的值为零(灰没有色相)]
h <- numeric(n)
notgray <- ( s != v )
## blue hue[#蓝色的色调]
idx <- (v == rgb[3,] & notgray )
if (any (idx))
h[idx] <- 2/3 + 1/6 * (rgb[1,idx] - rgb[2,idx]) / D[idx]
## green hue[#绿色色调]
idx <- (v == rgb[2,] & notgray )
if (any (idx))
h[idx] <- 1/3 + 1/6 * (rgb[3,idx] - rgb[1,idx]) / D[idx]
## red hue[#红色色调]
idx <- (v == rgb[1,] & notgray )
if (any (idx))
h[idx] <- 1/6 * (rgb[2,idx] - rgb[3,idx]) / D[idx]
## correct for negative red[#负面红色正确]
idx <- (h < 0)
h[idx] <- 1+h[idx]
## set the saturation[#设置饱和度]
s[! notgray] <- 0;
s[notgray] <- 1 - s[notgray] / v[notgray]
rbind( h=h, s=s, v=v )
}
## confirm the equivalence:[#确认等价:]
all.equal(rgb2hsv (rgb3),
rgb2hsvR(rgb3), tol=1e-14) # TRUE[真]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|