R语言RImagePalette包,图像照片提取调色板

R语言RImagePalette包,图像照片提取调色板
迁移照片颜色板


Snipaste_2020-12-06_01-28-19.png
001.jpg
002.jpg
003.png
Snipaste_2020-12-06_01-28-19.png
Snipaste_2020-12-06_01-38-44.png
Snipaste_2020-12-06_02-56-13.png
Snipaste_2020-12-06_02-56-32.png
Snipaste_2020-12-06_02-58-23.png
Snipaste_2020-12-06_02-58-49.png
# Sun Dec 06 01:05:47 2020 -

# 字符编码:UTF-8
# R 版本:R x64 4.0.3 for window 10
# [email protected]
# 个人笔记不负责任
# —— 拎了个梨
rm(list=ls());gc()

.rs.restartR()

library("RImagePalette")
require(jpeg) #  不支持中文路径
require(png) #  不支持中文路径
require(scales)
require(raster)
require(ggplot2)
# 假如你的工作目录有一个003.png的照片:
# 下同
#
# 预览:
readPNG('003.png') %>%
  display_image()
p <- readPNG('003.png')
image_palette(p,n = 3)
image_palette(p,n = 5) %>%
  show_col()
# Sun Dec 06 01:26:48 2020 --
readPNG('003.png') %>%
  image_palette(#  函数(如readJPG()或readPNG()的输出适合用作图像。
                n = 5 #  离散颜色数。
                ,choice = max #  Try median, or min, or max, or whatever summary statistic suits your fancy.
                ,volume = T #  启用高质量
                ) %>%
  show_col()

# Sun Dec 06 01:31:07 2020 -应用到别的照片-----------------------------
# 实现类似颜色搬迁的情况
require(raster)
require(RImagePalette)

par(nfrow=c(2,1))
p2 <- raster('001.jpg')
mycol <- jpeg::readJPEG('001.jpg') %>%
  image_palette(n = 10);BRRR::skrrrahh(25)

plot(p2) #  预览
plot(p2,col=mycol)
# Sun Dec 06 01:39:00 2020 -- 优雅书写
readJPEG('002.jpg') %>%
  image_palette(n = 100) %>%
  plot(raster('001.jpg'), col = .)

# Sun Dec 06 01:43:48 2020 ---矢量图,ggplot2---------------------------
require(ggplot2)

mycol <- readJPEG('002.jpg') %>%
  image_palette(n = 1) #  一个色
show_col(mycol)
ggplot(mtcars,aes(factor(cyl)))+
  geom_bar(fill = mycol)

# Sun Dec 06 01:56:27 2020 --多个颜色
mycol <- readJPEG('002.jpg') %>%
image_palette(n = 10) #  填上颜色数量
show_col(mycol)

# mycol <-
#   c(
#     "#868E69",
#     "#5A5450" ,
#     "#83A8A9",
#     "#668596",
#     "#ADA9A6",
#     "#13191B" ,
#     "#A5D4C9",
#     "#99DBF3",
#     "#C8FDBB" ,
#     "#FBF9EB"
#   )

data.frame(
  x=length(mycol) %>% rnorm() ,
  c=mycol
) %>%#names()
  ggplot()+
  geom_bar(aes(x = x,fill=c))+
  scale_fill_manual(values = mycol) #  填充色
# Sun Dec 06 02:55:40 2020 --
data.frame(
  x=length(mycol) %>% rnorm() ,
  y=length(mycol) %>% rnorm() ,
  c=mycol
) %>%#names()
  ggplot(aes(x = x,y = y,fill=c))+
  geom_col()+
  scale_fill_manual(values = mycol) #  填充色
# Sun Dec 06 02:55:50 2020 --
data.frame(
  x=length(mycol) %>% rnorm() ,
  y=length(mycol) %>% rnorm() ,
  c=mycol
) %>%#names()
  ggplot(aes(x = x,y = y))+
  geom_col(aes(colour = factor(c)))+
  scale_colour_manual(values = mycol) #  边色


# Sun Dec 06 02:46:10 2020 --
data.frame(
  x=length(mycol) %>% rnorm() ,
  y=length(mycol) %>% rnorm() ,
  c=mycol
) %>%#names()
  ggplot(aes(x = x,y = y))+
  geom_point(aes(colour = factor(c)))+
  scale_colour_manual(values = mycol)

你可能感兴趣的:(R语言RImagePalette包,图像照片提取调色板)