R語言RImagePalette包,圖像照片提取調(diào)色板
遷移照片顏色板
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
# cgh163email@163.com
# 個(gè)人筆記不負(fù)責(zé)任
# —— 拎了個(gè)梨??
rm(list=ls());gc()
.rs.restartR()
library("RImagePalette")
require(jpeg) # 不支持中文路徑
require(png) # 不支持中文路徑
require(scales)
require(raster)
require(ggplot2)
# 假如你的工作目錄有一個(gè)003.png的照片:
# 下同
#
# 預(yù)覽:
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(# 函數(shù)(如readJPG()或readPNG()的輸出適合用作圖像。
n = 5 # 離散顏色數(shù)。
,choice = max # Try median, or min, or max, or whatever summary statistic suits your fancy.
,volume = T # 啟用高質(zhì)量
) %>%
show_col()
# Sun Dec 06 01:31:07 2020 -應(yīng)用到別的照片-----------------------------
# 實(shí)現(xiàn)類似顏色搬遷的情況
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) # 預(yù)覽
plot(p2,col=mycol)
# Sun Dec 06 01:39:00 2020 -- 優(yōu)雅書寫
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) # 一個(gè)色
show_col(mycol)
ggplot(mtcars,aes(factor(cyl)))+
geom_bar(fill = mycol)
# Sun Dec 06 01:56:27 2020 --多個(gè)顏色
mycol <- readJPEG('002.jpg') %>%
image_palette(n = 10) # 填上顏色數(shù)量
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)