Skip to content

Instantly share code, notes, and snippets.

@juanchiem
Last active October 31, 2022 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanchiem/ec632a53e3050baa82d9ded4f8023148 to your computer and use it in GitHub Desktop.
Save juanchiem/ec632a53e3050baa82d9ded4f8023148 to your computer and use it in GitHub Desktop.
"https://tiagoolivoto.github.io/paper_pliman/code.html#batch-processing"
```{r}
# install.packages("BiocManager")
# BiocManager::install("EBImage")
# devtools::install_github("TiagoOlivoto/pliman")
pacman::p_load(tidyverse, pliman)
```
1. Seleccione el working directory
Ctrl + shift + h #EN MI CASO: "~/oidio_colza"
2. Importar una imagen de prueba
```{r}
img_test <- image_import("img_orig/img_04.png")
# en este caso elijo de una subcarpeta del WD que contiene las imagenes originales
```
3. Indicar background (back), sano (healthy) y sintomatico (symptom)
```{r}
x11() # esto hay que hacer en las ultimas versiones de RStudio por un bug que trae
healthy <- pick_palette(img_test)
symptom <- pick_palette(img_test)
back <- pick_palette(img_test)
image_combine(img_test, healthy, symptom, back, ncol = 4)
```
4. Medimos % severidad
```{r}
res <- measure_disease(
img = img_test,
img_healthy = healthy,
img_symptoms = symptom,
img_background = back,
col_background = "white", # default
col_lesions = "red", # default
col_leaf = "green",
show_contour = FALSE, # hide the contour line
show_original = FALSE, # create a mask
save_image = TRUE,
prefix = "proc_mask_",
dir_processed = "img_proc"
)
```
5. Resultados
```{r}
res$severity
# comparo original con procesada
proc_test <- image_import("img_proc/proc_mask_img.jpg")
image_combine(img_test, proc_test, ncol = 2)
```
6. Batch processing
```{r}
batch_res <- measure_disease(
dir_original = "img_orig" ,
pattern = "img",
dir_processed = "img_proc",
prefix = "proc_",
img_healthy = healthy,
img_symptoms = symptom,
img_background = back,
col_background = "white", # default
col_lesions = "red", # default
col_leaf = "green",
show_contour = FALSE, # hide the contour line
show_original = FALSE, # create a mask
save_image = TRUE,
verbose = FALSE,
parallel = TRUE
)
```
Resultado como tibble
```{r}
batch_res$severity %>% tibble
```
Extra: SAD con x niveles de las imagenes procesadas
```{r}
sad(batch_res, 4, ncol = 4)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment