Not enough input arguments in rgb2gray function

Hi, i´m a newbie in matlab. I´m tring to get a cilindrical projection of a planar image. The code is with this error "Error using projectIC (line 8) Not enough input arguments. ". I´m making some mistake inserting the image input, I1 (matrix), on the rgb2gray function I suppose. Can you help me? Thank you the code is the following:
% I1=imread('i1.bmp');
imshow(I1)
angle=33;
%
function [imageC] = projectIC(I1,angle)
ig = rgb2gray(I1);
[h w] = size(ig);
imageC = uint8(zeros(h,w));
alpha = angle/180*pi;
d = (w/2)/tan(alpha);
r = d/cos(alpha);
for x = -w/2+1:w/2
for y = -h/2+1:h/2
x1 = d * tan(x/r);
y1 = y * (d/r) /cos(x/r);
if x1 < w/2 && x1 > -w/2+1 && y1 < h/2 && y1 > -h/2+1
imageC(y+(h/2), x+(w/2) ) = ig(round(y1+(h/2)),round(x1+(w/2)));
end
end
end

2 Comments

@João Martinho Marques: do NOT attach code as an image. We cannot search for text in an image, we cannot edit an image, we cannot run an image, we cannot fix an image... if you have code then it is text, so please either include it in your question as text or upload it as a text file.
OK! I had modified the code to the text format! Thanks

Sign in to comment.

 Accepted Answer

Jan
Jan on 9 May 2017
Edited: Jan on 9 May 2017
Your function projectIC requires 2 inputs according to the definition:
function projectIC(I1, angle)
Then you have to provide these arguments, when you call the function:
projectIC(I1, angle)
With calling projectIC only, the arguments are missing and the rgb2gray does not have an input.

3 Comments

I had defined the variables on the workspace with the first part of the code. It´s not enough to provide the arguments to the function?
I1=imread('i1.bmp');
imshow(I1)
angle=33;
No, having the variabvles in the workspace is not enough. See this example for a function:
x = 1.2;
y = 0.1;
sin % FAILS!
Here sin is called without inputs also and Matlab cannot guess, if you want the sin of x or of y. Your case is exactly the same, althozugh you use the same names for the variables in the definition of the function and in the command window. But this does not matter, because the names inside function are completely independent. The implementation of sin() can be:
function StandardOutput = sin(AbsurdInputName)
And if you call the sin function you will not have to consider the internal names in any way. This is the nature and the purpose of functions: Hide the internal details such that the function can be used without needing to know, what's going on inside.
And in your case this means, that you have to call the function with input arguments:
projectIC(I1, angle)
Or if you use different names:
ImageOne = imread('i1.bmp');
angleAroundAxis = 33;
projectIC(ImageOne, angleAroundAxis)

Sign in to comment.

More Answers (0)

Categories

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!