diff --git a/.gitignore b/.gitignore index 413247d..5abaa90 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ docs/ # translation temp files po/*~ +images/ +images_mosaiques.Rproj +res/ diff --git a/exemple_mosaique_r_imagemagick.R b/exemple_mosaique_r_imagemagick.R new file mode 100644 index 0000000..e38dc9d --- /dev/null +++ b/exemple_mosaique_r_imagemagick.R @@ -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")