"Error, Not enough input arguments"
5 views (last 30 days)
Show older comments
Hi everyone, I am making code that takes a picture, applies a threshold to the picture, then locates the pixel value of a certain area of interest in the picture. I am getting an error on line 14 saying there is not enough input arguments? I cannot solve this for the life of me. Any ideas? My code is here:
function [BW,maskedRGBImage_2] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder App. The colorspace and
% minimum/maximum values for each channel of the colorspace were set in the
% App and result in a binary mask BW and a composite image maskedRGBImage,
% which shows the original RGB image values under the mask BW.
% Auto-generated by colorThresholder app on 27-Apr-2016
%------------------------------------------------------
% Convert RGB image to chosen color space
Original_Picture = RGB;
% Define thresholds for channel 1 based on histogram settings
channel1Min = 149.000;
channel1Max = 255.000;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 140.000;
channel2Max = 255.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 140.000;
channel3Max = 255.000;
% Create mask based on chosen histogram thresholds
BW = (Original_Picture(:,:,1) >= channel1Min ) & (Original_Picture(:,:,1) <= channel1Max) & ...
(Original_Picture(:,:,2) >= channel2Min ) & (Original_Picture(:,:,2) <= channel2Max) & ...
(Original_Picture(:,:,3) >= channel3Min ) & (Original_Picture(:,:,3) <= channel3Max);
% Initialize output masked image based on input image.
maskedRGBImage_2 = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage_2(repmat(~BW,[1 1 3])) = 0;
%AFTER PAPER IS FOUND AND THRESHOLDED TO WHITE, THE FOLLOWING CODE LOCATES
%AREA OF INTEREST
Image_Size=size(maskedRGBImage_2);
x = Image_Size(2);
y = Image_Size(1);
s = zeros(1,350); %Array of test pixels
top_left_x = 0;
top_left_y = 0;
for y = 1:3168;
for x = 1:4752;
Test_pixel = maskedRGBImage_2(y,x);
if Test_pixel == 255
for k = x:(x+349);
%Generates value of test pixel
g = maskedRGBImage_2(y, k);
%Populates array of test pixels
f = k - x + 1;
s(1,f) = g;
g_sum = nnz(s);
if g_sum > 330; %This is 0.95*white line so 330/350 pixels are white
top_left_x = x;
top_left_y = y;
return
end
end
end
end
end
% Convert RGB image to chosen color space. Cropped based on original normal
% test pics
Original_Picture = imcrop(rgb2hsv(RGB),[x y (x+350)-x (y+450)-y]);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.063;
channel1Max = 0.096;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.111;
channel2Max = 0.131;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.612;
channel3Max = 0.647;
% Create mask based on chosen histogram thresholds
BW = (Original_Picture(:,:,1) >= channel1Min ) & (Original_Picture(:,:,1) <= channel1Max) & ...
(Original_Picture(:,:,2) >= channel2Min ) & (Original_Picture(:,:,2) <= channel2Max) & ...
(Original_Picture(:,:,3) >= channel3Min ) & (Original_Picture(:,:,3) <= channel3Max);
% Invert mask
BW = ~BW;
% Initialize output masked image based on input image.
maskedRGBImage_2 = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage_2(repmat(~BW,[1 1 3])) = 0;
%trial 3 edited on 4th may 2016
Please help! Many thanks,
Ellis
0 Comments
Answers (1)
Guillaume
on 5 May 2016
Assuming that line 14 is the first line of code of your function:
Original_Picture = RGB;
The error message is telling you that your function expects one argument, yet you passed zero when you called it. The error is triggered on line 14 because it's the first line where you attempt to use the required argument.
The fix is simple, pass an image when you call your function:
[out1, out2] = createMask(someimage); %return values are optional, input is not
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!