Convert colors to imitate greyscale printing

2019-02-25 04:18发布

问题:

When reading this question, I started to think whether it would be possible to convert colors to imitate an average greyscale printer (assuming that your screen is calibrated)? Finding an approvable approximation would save paper.

For example, how to convert these colors to see whether the light and dark blues and reds can be differentiated on paper?

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))

回答1:

Use an HCL palette with chroma set to zero to create greyscale values that are indistinguishable to the human eye.

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)

If you want to generate the greys from your original colours, use the scales package.

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


回答2:

The col2grey (and/or col2gray) function in the TeachingDemos package uses one common method for doing this. The idea is to see what your colors will look like when printed or copied in grayscale instead of color.



回答3:

The desaturate() function in the `colorspace package can also be used to convert colors to their gray levels only. This collapses chroma (colorfulness) in the HCL (or polar CIELUV) representation of the colors.

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:

You can use one of the 3 conversion algorithms outlined here, and just determine if they're outside whatever tolerance you think is too similar.