Reputation:
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
Upvotes: 0
Views: 1231
Reputation: 3402
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.
Upvotes: 0
Reputation: 74940
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.
Upvotes: 4