【发布时间】:2020-05-14 15:35:27
【问题描述】:
这里的目标是使用魔法读取和带注释的图像以类似网格的方式设置图像。我可以读取、注释图像,并以 3 组(即 3 列)为一组。我只是不知道如何将这些组堆叠在一起。 这是期望的结果,但不够灵活(?),而且 image_ggplot() 非常缓慢:
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)
这是我从地面构建它的尝试:
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 堆叠在一起,这些都不起作用:
lapply(list_of_rows,function(x){image_append(x,stack=T)})
do.call(c,list_of_rows)
只是在寻找一种灵活的方式来在我可以控制的列数中排列 4-32 张图像(不知道每次的图像总数)。
【问题讨论】:
-
您可以使用等效的 -append 或 -smush 进行堆叠,或者使用蒙太奇制作网格。
标签: r imagemagick