使用“ imager”包中的load.image()函数在R中加载多个图像

时间:2019-04-06 11:53:44

标签: r loadimage

我想使用“ imager”包中提供的load.image()函数加载多个图像,但是出现“找不到文件”消息错误。有人可以帮我解决这个问题吗?

我试图加载列表中的图像,并将此列表作为参数添加到load.image()函数,但是它只能读取一个文件,因此该列表是不可接受的。此后,我尝试使用for循环在列表中进行迭代,并将循环中的索引添加为参数,然后出现以下问题:“ wrap.url(file,load.image.internal)中的错误:File找不到”

filenames <- list.files("~/Downloads/project", pattern="*.JPG")

for(idx in filenames) {
   load.image(idx)
   "I tried here with concatenate the idx with the path string, but with no success"
   load.image(paste("~/Downloads/project",idx))  
}

1 个答案:

答案 0 :(得分:0)

尝试将full.names = T选项添加到list.files。这样会将完整路径添加到文件,如果不存在,则仅返回文件名。

list.files("~/Downloads/project", pattern="*.JPG", full.names = T)

然后在循环中load.image(idx)