导入多个PNG图像

时间:2017-07-25 08:00:37

标签: r image image-processing import

如何导入多个png图像?我使用的是R v3.4.1。

EBImagesreadImages个软件包在此版本中不可用

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))

如果有人有更好的解决方案,请分享!

1 个答案:

答案 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)