在R版本3.5.2上从JPEG图像中查找调色板

时间:2019-01-19 19:35:00

标签: r jpeg palette

我正在尝试查找图像的调色板。我发现了一些代码示例,但是在查找当前R版本(3.5.2)支持的软件包时遇到了问题。我无法安装所需的软件包(readJPEG,dim等),并且想知道是否有解决方法或可用的更新版本。我一直在关注paletteR,请点击下面的链接。感谢您的协助。

https://datascienceplus.com/how-to-use-paletter-to-automagically-build-palettes-from-pictures/

1 个答案:

答案 0 :(得分:1)

有几个软件包可以做到这一点。我个人喜欢cuttlefish

# devtools::install_github("jcbain/cuttlefish")
colours_vector <- cuttlefish::create_palette("example.jpg", n = 32)

这是一个使用蒙娜丽莎作为调色板的简单示例:

library(ggplot2)
mona_lisa <- 
  "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/800px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg"

colours_vector_mlisa <- cuttlefish::create_palette(mona_lisa, n = 7)
ggplot(mpg, aes(displ, hwy, colour = class)) + 
  geom_point() +
  scale_color_manual(values = colours_vector_mlisa)

enter image description here