首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R中的魔术图像网格

R中的魔术图像网格
EN

Stack Overflow用户
提问于 2020-05-14 23:35:28
回答 1查看 450关注 0票数 1

这里的目标是使用magick read和带注释的图像以网格方式设置图像。我可以读取、注释图像,并以3列为一组(即3列)。我只是想不出如何将这些组堆叠在一起。这是预期的结果,但不灵活(?)而且image_ggplot()慢得让人痛苦:

代码语言:javascript
复制
grid.arrange(image_ggplot(annotated_images[[1]]),image_ggplot(annotated_images[[2]]),
             image_ggplot(annotated_images[[3]]),image_ggplot(annotated_images[[4]]),
             image_ggplot(annotated_images[[5]]),image_ggplot(annotated_images[[6]]),
             image_ggplot(annotated_images[[7]]),image_ggplot(annotated_images[[8]]),
             image_ggplot(annotated_images[[9]]),image_ggplot(annotated_images[[10]]),
             image_ggplot(annotated_images[[11]]),ncol=3)

下面是我从地面开始构建它的尝试:

代码语言:javascript
复制
newlogo <- image_read("https://jeroen.github.io/images/Rlogo.png")
images=rep(newlogo,11)
chunk_images=split(images, ceiling(seq_along(images)/3))
annotated_images=lapply(images,function(x){
  image_annotate(image_read("https://jeroen.github.io/images/Rlogo.png"), paste0('Random Number: ',rnorm(1)), color = 'white',boxcolor='grey10', size = 23)
})
list_of_rows=lapply(chunk_images,function(x){image_append(c(image_annotate(x, paste0('Random Number: ',rnorm(1)), color = 'white',boxcolor='grey10', size = 23)))})
#list_of_rows[1] == 3 images side-by-side
#list_of_rows[2] == 3 images side-by-side
#list_of_rows[3] == 3 images side-by-side
#list_of_rows[4] == the remaining 2 images

我想要将list_of_rows堆叠在一起,这两个都不起作用:

代码语言:javascript
复制
lapply(list_of_rows,function(x){image_append(x,stack=T)})
do.call(c,list_of_rows)

只是寻找一种灵活的方式来安排在我可以控制的列数从4-32个图像的任何地方(不会知道每次图像的总数)。

EN

回答 1

Stack Overflow用户

发布于 2020-11-13 01:12:37

正如@fmw42在评论中所建议的,您可以使用函数image_montagetile parameter来控制列的排列

代码语言:javascript
复制
newlogo <- "https://jeroen.github.io/images/Rlogo.png"
images=rep(newlogo,11)
img <- magick::image_read(images) %>%
  magick::image_montage(tile = '3')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61801420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档