-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-to-df.R
42 lines (40 loc) · 882 Bytes
/
convert-to-df.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
hex_to_num <- function( hex ){
# Aca falta check de validez del input
paste0("0x", hex) %>%
as.numeric()
}
to_RGB_df <- function(my_image){
mis_colores <- my_image %>%
as.raster() %>%
as.matrix() %>%
as.vector()
colores_df <- data.frame(
R = str_sub(mis_colores,2,3),
G = str_sub(mis_colores,4,5),
B = str_sub(mis_colores,6,7)
)
colores_df %>%
mutate(
R=hex_to_num(R),
G=hex_to_num(G),
B=hex_to_num(B)
)
}
convert_to_RGB_df <- function(filename){
my_image <- image_read(filename)
mis_colores <- my_image %>%
as.raster() %>%
as.matrix() %>%
as.vector()
colores_df <- data.frame(
R = str_sub(mis_colores,2,3),
G = str_sub(mis_colores,4,5),
B = str_sub(mis_colores,6,7)
)
colores_df %>%
mutate(
R=hex_to_num(R),
G=hex_to_num(G),
B=hex_to_num(B)
)
}