问题
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