如何将 .csv 文件中列出的图像名称加载到 R 中
我使用下面的简单代码将多个图像与 R magick 包一起附加。它运行良好,但是有许多图像需要处理,并且它们的名称存储在 .csv 文件中。任何人都可以建议如何将图像名称从 .csv 文件中的特定单元格加载到 image_read 函数(请参阅代码下面的示例)?到目前为止,我无法找到任何合适的方法来解决这个问题。
library (magick)
pic_A <- image_read('A.png')
pic_B <- image_read('B.png')
pic_C <- image_read('C.png')
combined <- c(pic_A, pic_B, pic_C)
combined <- image_scale(combined, "300x300")
image_info(combined)
final <- image_append(image_scale(combined, "x120"))
print(final)
image_write(final, "final.png") #to save
I am using a simple code below to append multiple images together with the R magick package. It works well, however, there are many images to process and their names are stored in a .csv file. Could anyone advise on how to load the image names to the image_read function from specific cells in a .csv file (see example below the code)? So far, I was not able to find anything appropriate that would solve this.
library (magick)
pic_A <- image_read('A.png')
pic_B <- image_read('B.png')
pic_C <- image_read('C.png')
combined <- c(pic_A, pic_B, pic_C)
combined <- image_scale(combined, "300x300")
image_info(combined)
final <- image_append(image_scale(combined, "x120"))
print(final)
image_write(final, "final.png") #to save
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该有效。如果您将 csv 加载到数据框中,则可以直接将
image_read
指向适当的元素。并且索引(行号)包含在输出文件名中,这样每次迭代就不会被覆盖。
Something like this should work. If you load the csv into a dataframe then, it's then straightforward to point the
image_read
towards the appropriate elements.And the index (row number) is included in the output filename so that things are not overwritten each iteration.