0

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

Edit: 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);
Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
  • I don't understand what the desired behavior is here. Where do the `load.image` and `grayscale` functions come from? – MrFlick Apr 08 '19 at 19:04
  • Hello. Both load.image and grayscale functions coming from a package, called "imager". The im1 = grayscale(im); line comes from an older code, where it worked when only one file was loaded with this load.image() function, so this error appeared when i tried to use it in the grayscale() function with the index from the list. – Bálint Molnár Apr 09 '19 at 07:08

0 Answers0