col2value.Rd
Transform back from colors to values
col2value(r, g, b, col_fun)
r | red channel in |
---|---|
g | green channel in |
b | blue channel in |
col_fun | the color mapping function generated by |
colorRamp2
transforms values to colors and this function does the reversed job.
Note for some color spaces, it cannot transform back to the original value perfectly.
A vector of original numeric values.
x = seq(0, 1, length = 11) col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red")) col = col_fun(x) col2value(col, col_fun = col_fun)#> [1] 0.0000000 0.1011984 0.2025821 0.3036648 0.4024652 0.5000000 0.5898071 #> [8] 0.6857470 0.7876882 0.8938379 1.0000000col2value("red", col_fun = col_fun)#> [1] 1col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"), space = "sRGB") col = col_fun(x) col2value(col, col_fun = col_fun)#> [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0