簡體   English   中英

使用“imager”包中的load.image()函數在R中加載多個圖像

[英]Load more than one image in R with load.image() function from “imager” package

我想用“imager”包中提供的load.image()函數加載多個圖像,但是我遇到了“找不到文件”消息的錯誤。 有人可以幫我解決這個問題嗎?

我試圖在列表中加載圖像,並將此列表作為參數添加到load.image()函數,但它只能讀取一個文件,因此列表是不可接受的。 在此之后我嘗試使用for循環在列表中進行迭代,並從循環中添加索引作為參數,我遇到了這個問題:“wrap.url中的錯誤(文件,load.image.internal):文件未找到”

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

嘗試將full.names = T選項添加到list.files 這會添加文件的完整路徑,如果不存在,則僅返回文件名。

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

然后在你的循環中只load.image(idx)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM