0
votes

I keep getting this error when inputting this code. Im trying to eventually convert a color image to greyscale using nested for loops. Heres the error message "Undefined function 'avg' for input arguments of type 'double'"

x = imread('RickMoranis.jpg');
r = size(x, 1);
c = size(x, 2);

 for row = 1:r 
    for col = 1:c 
       y= mean(avg(row,col,:));
    end
end
end
2
I don't think avg is a matlab function, do you mean mean? (The error is saying it doesn't know what the function avg is) - mathematical.coffee

2 Answers

4
votes

There is no built-in function avg.

Most likely, you wanted to write

y= mean(x(row,col,:));

Note that instead of the double loop, you can also write

y = mean(x,3);

Finally, if you have the Image Processing Toolbox, you way want to check out rgb2gray for conversion of RGB to grayscale.

0
votes

If you are expecting avg to calculate the average, use mean. It seems you already have the command mean in your code. There is no built-in function avg in matlab.