我正在尝试做一些图像识别的精灵宝可梦图片,我已经下载了一个文件夹,里面有很多精灵宝可梦图片。我有BiocManager包的库EBImage,并使用下面的代码创建了一个镜像到csv中。但是,有没有一种方法可以用for循环自动调用文件夹中的所有图像呢?
install.packages("BiocManager")
BiocManager::install("EBImage")
library("EBImage")img <- readImage("c:/Users/hlop5/Downloads/images/pikachu.png")
img <- channel(img,"grey")
display(img, method = "raster")
write.csv(t(img), "sample.csv",row.names = FALSE)
sample <- read_csv("C:/sample.csv")发布于 2021-05-15 14:47:58
您可以尝试:
filenames <- list.files('C:/Users/hlop5/Downloads/images/',
pattern = '\\.png', full.names = TRUE)
apply_function <- function(file) {
img <- readImage(file)
img <- channel(img,"grey")
write.csv(data.frame(t(img)),
paste0(sub('png$', 'csv', basename(file))),row.names = FALSE)
}
lapply(filenames, apply_function)https://stackoverflow.com/questions/67541312
复制相似问题