-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.R
50 lines (42 loc) · 994 Bytes
/
main.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library(tidyverse)
library(jpeg)
setwd("C:/Users/Wenyao/Desktop/R/8bit_pug")
source("./functions.R")
color_palette <- c(
"#927f5e", #fawn
"#0a0e11", #black
"#972228", #red
"#f1f1fb" #grey
) %>%
col2rgb() %>%
t() %>%
`/`(255)
input <- readJPEG("./images/input.jpg")
image <- tidy_image(input) %>%
downscale_image(target_image_size = 50)
colored_images <- lapply(
1:16,
get_color_palette_with_noise,
color_palette = color_palette,
size = 101,
sd = 0.05
) %>%
lapply(
match_color,
image = image
) %>%
bind_rows(.id = "SEED") %>%
mutate(SEED = factor(SEED, levels = SEED %>% as.numeric() %>% max() %>% seq()))
plot <- ggplot(colored_images, aes(x = x, y = -y, fill = fill)) +
geom_tile() +
scale_fill_identity() +
coord_fixed() +
theme_void() +
theme(
strip.text = element_blank()
) +
facet_wrap(~SEED, ncol = 4)
print(plot)
jpeg(filename = "./images/output.jpg", width = 1000, height = 1000, quality = 100)
plot
dev.off()