【问题标题】:Convert colors to imitate greyscale printing转换颜色以模仿灰度打印
【发布时间】:2014-01-08 01:42:52
【问题描述】:

在阅读this question 时,我开始思考是否可以转换颜色以模仿普通的灰度打印机(假设您的屏幕已校准)?找到一个可以接受的近似值会节省纸张。

例如,如何转换这些颜色,看看在纸上是否可以区分浅蓝色和深蓝色和红色?

temp <- rgb2hsv(239, 138, 98, maxColorValue=255)
Rl <- hsv(h = temp[1,], s = 0.5, v = 1)
Rd <- hsv(h = temp[1,], s = 0.5, v = 0.4)
temp <- rgb2hsv(103, 169, 207, maxColorValue=255)
Cl <- hsv(h = temp[1,], s = temp[2,], v = 1)
Cd <- hsv(h = temp[1,], s = temp[2,], v = 0.4)

plot(1:4, type = "p", col = c(Rl, Rd, Cl, Cd), pch = 19, cex = 8, xlim = c(0,5), ylim = c(0,5))

【问题讨论】:

  • 如果你在 hsv 中工作,你可以将饱和度设置为零以转换为灰度。
  • 如果您希望在灰度模式下人类无法区分颜色,请使用 hcl 调色板,并将色度设置为零。
  • 在 hsv 刻度上将饱和度设置为 0 会使 Rl 消失,但如果您尝试使用灰度打印机打印绘图,则不会。也许打印机调整了颜色?

标签: r graphics colors


【解决方案1】:

使用色度设置为零的 HCL 调色板来创建人眼无法区分的灰度值。

library(colorspace)
n <- 10
cols <- rainbow_hcl(n)
plot(seq_len(n), cex = 5, pch = 20, col = cols)

greys <- rainbow_hcl(n, c = 0)
plot(seq_len(n), cex = 5, pch = 20, col = greys)

如果您想从原始颜色生成灰色,请使用 scales 包。

library(scales)
greys2 <- col2hcl(cols, c = 0)
plot(seq_len(n), cex = 5, pch = 20, col = greys2)

【讨论】:

  • 为什么无法区分?
  • 您的问题是颜色是否“可以在纸上区分”。 HCL 纠正了在 HSV 中蓝色看起来比具有相同饱和度和值的黄色更暗的事实。
  • 好的,感谢scales 包。所以我的问题的答案类似于:cols &lt;- c(Rl, Rd, Cl, Cd); library(scales); greys &lt;- col2hcl(cols, c = 0); plot(seq_along(cols), cex = 5, pch = 20, col = greys)。我没有打印机来检查转为灰度的颜色目前在屏幕和纸张上看起来是否大致相同。
【解决方案2】:

TeachingDemos 包中的col2grey(和/或col2gray)函数使用一种常用方法来执行此操作。我们的想法是查看以灰度而不是彩色打印或复制时您的颜色会是什么样子。

【讨论】:

    【解决方案3】:

    `colorspace 包中的desaturate() 函数也可用于仅将颜色转换为其灰度级。这会在颜色的 HCL(或极性 CIELUV)表示中折叠色度(色彩)。

    plot(1:4, type = "p",
      col = colorspace::desaturate(c(Rl, Rd, Cl, Cd)),
      pch = 19, cex = 8, xlim = c(0,5), ylim = c(0,5))
    

    【讨论】:

      【解决方案4】:

      您可以使用here 列出的 3 种转换算法之一,并确定它们是否超出您认为过于相似的任何容差。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-29
        • 2014-01-11
        • 1970-01-01
        相关资源
        最近更新 更多