Problem solved! - List element set as parameter to grayscale() function leads to error

[亡魂溺海] 提交于 2019-12-25 01:39:38

问题


I've loaded images with load.image() function to a list, and when I wanted to add the index from the list as the parameter to a function called grayscale(), I've got the following error:

Error in if (spectrum(im) == 1) { : argument is of length zero

Could someone please help me in this problem?

filenames <- list.files("~/Downloads/project", pattern="*.jpg", full.names = T)
if(!is.null(filenames)){
  for(idx in filenames) {
    im <- idx
    print(im)
    load.image(im)

    im1=grayscale(im);

Problem is solved now:

load.image(im) should be saved to a variable, and this one should be added as the parameter for the grayscale() function

filenames <- list.files("~/Downloads/project", pattern="*.jpg", full.names = T)
if(!is.null(filenames)){
  for(idx in filenames) {
    im <- idx
    print(im)
    loaded_image <- load.image(im)

    im1=grayscale(loaded_image);

来源:https://stackoverflow.com/questions/55580110/problem-solved-list-element-set-as-parameter-to-grayscale-function-leads-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!