ajout du programme R
This commit is contained in:
parent
646cc716be
commit
ca63b98dad
2 changed files with 74 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -45,3 +45,6 @@ docs/
|
|||
# translation temp files
|
||||
po/*~
|
||||
|
||||
images/
|
||||
images_mosaiques.Rproj
|
||||
res/
|
||||
|
|
71
exemple_mosaique_r_imagemagick.R
Normal file
71
exemple_mosaique_r_imagemagick.R
Normal file
|
@ -0,0 +1,71 @@
|
|||
library(magrittr)
|
||||
library(here)
|
||||
library(magick)
|
||||
|
||||
repertoire.images <-
|
||||
paste0(here(),"/images/")
|
||||
|
||||
repertoire.res <-
|
||||
paste0(here(),"/res/")
|
||||
|
||||
nom.fichiers.images <- paste0(repertoire.images,
|
||||
list.files(repertoire.images,
|
||||
pattern=".*\\.jpg",
|
||||
include.dirs = FALSE,
|
||||
recursive = FALSE))
|
||||
|
||||
dir.create(repertoire.res, recursive = TRUE)
|
||||
|
||||
# Images Drawbook
|
||||
image_drawbook <- function(image) {
|
||||
image %>%
|
||||
image_resize("400x300!",
|
||||
filter = "Lanczos") %>%
|
||||
image_quantize(colorspace = "gray",
|
||||
dither = TRUE) %>%
|
||||
image_edge() %>%
|
||||
image_negate() %>%
|
||||
image_normalize() %>%
|
||||
image_threshold(type = "black",
|
||||
threshold = "55%") %>%
|
||||
image_despeckle() %>%
|
||||
image_blur(radius = 1, sigma = 0.5) %>%
|
||||
image_contrast(sharpen = 1) %>%
|
||||
image_extent(geometry = "400x300",
|
||||
gravity = "center",
|
||||
color = "white")
|
||||
}
|
||||
|
||||
image_read(nom.fichiers.images) %>%
|
||||
image_drawbook() %>%
|
||||
image_montage(geometry = "400x300",
|
||||
tile = "5x5",
|
||||
bg = "white") %>%
|
||||
image_write(paste0(repertoire.res,
|
||||
"montage_drawbook.png"),
|
||||
format = "png")
|
||||
|
||||
# Images Sharp
|
||||
|
||||
image_sharp_400 <- function(image) {
|
||||
image %>%
|
||||
image_resize("400x300!",
|
||||
filter = "Lanczos") %>%
|
||||
image_normalize() %>%
|
||||
image_despeckle() %>%
|
||||
image_blur(radius = 1,
|
||||
sigma = 0.5) %>%
|
||||
image_contrast(sharpen = 1) %>%
|
||||
image_extent(geometry = "400x300",
|
||||
gravity = "center",
|
||||
color = "black")
|
||||
}
|
||||
|
||||
image_read(nom.fichiers.images) %>%
|
||||
image_sharp_400() %>%
|
||||
image_montage(geometry = "400x300",
|
||||
tile = "5x5",
|
||||
bg = "black") %>%
|
||||
image_write(paste0(repertoire.res,
|
||||
"montage_sharp.png"),
|
||||
format = "png")
|
Loading…
Reference in a new issue