Skip to content

Commit

Permalink
Clase 2022 24 10 (#7)
Browse files Browse the repository at this point in the history
* Notas de clase y funciones nuevas

* work on #3

* work on #3

* For #4

* Notas para #4

* Notas de clase CORRECTO #4

* para el issue #3
  • Loading branch information
dietrichson authored Oct 24, 2022
1 parent dbf92fe commit 8cbf6e9
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 7 deletions.
2 changes: 1 addition & 1 deletion analizar-foto.R → R/analizar-foto.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source("foto-a-dataframe.R")

analizar_foto <- function(filename){
tmp <- foto_a_dataframe(filename = filename) %>%
select(R, B, G)
Expand Down
25 changes: 25 additions & 0 deletions R/colores-primarios.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

colores_primarios <- tribble(
~color_name, ~R, ~G, ~B,
"Black" ,0,0,0,
"White" ,255,255,255,
"Red" ,255,0,0,
"Lime" ,0,255,0,
"Blue" ,0,0,255,
"Yellow" ,255,255,0,
"Aqua" ,0,255,255,
"Fuchsia" ,255,0,255,
"Silver" ,192,192,192,
"Gray", 128,128,128,
"Maroon" ,128,0,0,
"Olive" ,128,128,0,
"Green" ,0,128,0,
"Purple" ,128,0,128,
"Teal" ,0,128,128,
"Navy" ,0,0,128
) %>%
mutate(hex=rgb(R,G,B,maxColorValue = 255)) %>%
mutate(value = hex_to_num(str_sub(hex,2,7)) %>% as.integer())



42 changes: 42 additions & 0 deletions R/convert-to-df.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
)
}
19 changes: 19 additions & 0 deletions R/foto-a-dataframe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
foto_a_dataframe <- function(filename){
my_image <- image_read(filename)
mis_colores <- my_image %>%
as.raster() %>%
as.matrix() %>%
as.vector()
colores_df <- data.frame(
Red = str_sub(mis_colores,2,3),
Green = str_sub(mis_colores,4,5),
Blue = str_sub(mis_colores,6,7)
)
colores_df %>%
mutate(
R=hex_to_num(Red),
G=hex_to_num(Green),
B=hex_to_num(Blue)
) -> tmp
tmp
}
2 changes: 2 additions & 0 deletions R/libraries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library(tidyverse)
library(magick)
2 changes: 0 additions & 2 deletions visualizar-colores.R → R/visualizar-colores.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source("foto-a-dataframe.R")
source("analizar-foto.R")
colores_barchart <- function(filename){
my_data <- analizar_foto(filename)

Expand Down
8 changes: 4 additions & 4 deletions notas-de-clase-2022-10-05.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ analizar_foto()
paste0("./tmp/",my_data$filename[41]) %>%
analizar_foto()
```

```{r}
paste0("./tmp/",my_data$filename[41]) %>%
image_read() %>%
Expand All @@ -157,10 +158,9 @@ Crudo analisis, hay que buscar la manera de agregar matices

### Tarea:

* Extraer las funciones del documento
* Agregarlos a un documento .R
* Reutilizarlo en otro documento qmd

- Extraer las funciones del documento
- Agregarlos a un documento .R
- Reutilizarlo en otro documento qmd

### Nota

Expand Down
15 changes: 15 additions & 0 deletions notas-de-clase-2022-10-24.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "Notas de la clase de 24 de noviembre del 2022"
format: html
editor: visual
---

## Cargar todas las funciones de la capeta R

```{r}
my_files <- dir("R",full.names = TRUE)
for(archivo in my_files){
source(archivo)
cat("Procesando:", archivo, "\n")
}
```

0 comments on commit 8cbf6e9

Please sign in to comment.