如何导入多个png图像?我使用的是R v3.4.1。
EBImages
和readImages
个软件包在此版本中不可用
library(png)
img_train <- list.files(path = "file path",pattern = ".png",
all.files = TRUE,
full.names = TRUE, no.. = TRUE)
list_of_images <- lapply(img_train, readPNG)
转换为矩阵
image_matrix <- do.call('cbind', lapply(list_of_images, as.numeric))
如果有人有更好的解决方案,请分享!
答案 0 :(得分:0)
EBImage 可从Bioconductor存储库获取,有关安装说明,请参阅I want to use EBImage package but it says it is not available for my version of R
的答案。然后,您可以使用readImage
函数将多个图像作为数组或列表导入。
library("EBImage")
img_train <- list.files(path = "file path", pattern = ".png",
all.files = TRUE,full.names = TRUE,no.. = TRUE)
## image array
img_array <- readImage(img_train)
## image list
img_list <- lapply(img_train, readImage)