I am a begginer. I got error saying "Not enough input arguments." etc

2 次查看(过去 30 天)
I got error and I have no idea how I cna fix it.
COuld you teach me how to fix it, please.
Also, could you check if my codes meet the requirement or not, please??
Assignment details
1. The first function should filter the image with masks to identify the edges and
their orientations.
ˆ Label = 1 for horizontal edges
ˆ Label = 2 for vertical edges
ˆ Label = 3 for 45 degree edges
ˆ Label = 4 for 135 degree (that is -45 degree) edges
ˆ Label = 5 for non-edge pixels, i.e. magnitude of edge is below a given threshold
Tasks 2: Test your code with the two provided images (Image1 and Image2) and display
your results as indexed images with 5 levels if you use the first function and with
4 levels if you use the second function. For each function, compare the results using 2
different (very different) thresholds to decide if the edges are strong enough.
Error message
[EdgeImg, IndexImg] = Function1(InputImg,Threshold);
Error using length
Not enough input arguments.
Error in Function1 (line 28)
IndexImg = len*ones(size(InputImg));
Here is my code
function [EdgeImg, IndexImg] = Function1(InputImg, Threshold)
% Four masks for the entire image
H = [-1 -1 -1; 2 2 2; -1 -1 -1];
V = H';
D45 = [2 -1 -1; -1 2 -1; -1 -1 2];
D135 = [-1 -1 2; -1 2 -1; 2 -1 -1];
% Compute edge strengths and orientations using the four masks
R1 = imfilter(InputImg, H, 'symmetric');
R2 = imfilter(InputImg, V, 'symmetric');
R3 = imfilter(InputImg, D45, 'symmetric');
R4 = imfilter(InputImg, D135, 'symmetric');
% Initial Edgelmg and Indexlmh
EdgeImg = zeros(size(InputImg));
IndexImg = len*ones(size(InputImg));
% Now, loop applied through the pixels at edge using for
for k = 1:size(InputImg,1)
for m = 1:size(InputImg,2)
[R, jip] = max([R1(k,m), R2(k,m), R3(k,m), R4(k,m)]);
if R >= Threshold
EdgeImg(k,m) = R;
IndexImg(k,m) = jip;
else
EdgeImg(k,m) = 0;
IndexImg(k,m) = 5;
end
end
end
figure;
subplot(1,2,1);
imshow(EdgeImg);
title('Edge Image');
subplot(1,2,2);
imshow(IndexImg, []);
title('Index Image');
end
>> InputImg = imread('Image1.jpg');
>> Threshold = 50;
>> [EdgeImg, IndexImg] = Function1(InputImg,Threshold);
Error using length
Not enough input arguments.
Error in Function1 (line 28)
IndexImg = length*ones(size(InputImg));
  1 个评论
DGM
DGM 2023-4-26
length() is a function and requires an input argument.
len is not defined in the given code, but if the given usage of len throws that error, then it must be defined as a function somewhere which internally calls length().
It's not clear why you'd be calling length() at all in this scenario.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2023-4-26
Try this:
IndexImg = ones(size(InputImg), class(InputImg));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by