在 R 中转换 RGB 和 HEX 中的 Lab 颜色值

Bor*_*ino 3 rgb hex r color-space cielab

使用 R 很容易RGBHEX值转换为值:

    x <- c("165 239 210", "111 45 93")
    sapply(strsplit(x, " "), function(x)
    rgb(x[1], x[2], x[3], maxColorValue=255))
    #[1] "#A5EFD2" "#6F2D5D"
Run Code Online (Sandbox Code Playgroud)

如何将 CIELab 值转换为 RGB 和 HEX?

x <- c("20 0 0", "50 0 0")
[...code...]
#[1] "#303030" "#777777"
Run Code Online (Sandbox Code Playgroud)

mis*_*use 5

这是一种使用方法 library(colorspace)

library(colorspace)

z <- c("20 0 0", "50 0 0")
b <- do.call(rbind, lapply(strsplit(z, split = " "), as.numeric))
b <- LAB(b)
as(b, "RGB")
#output:
              R          G          B
[1,] 0.02989077 0.02989025 0.02989294
[2,] 0.18418803 0.18418480 0.18420138
Run Code Online (Sandbox Code Playgroud)

它不能直接转换为HEX,但可以转换为:RGB、XYZ、HSV、HLS、LAB、polarLAB、LUV、polarLUV。