I am MATLAB beginner, and I got stuck because of some error. Not enough input arguments. Error in Function1 (line 15) R1 = imfilter(InputImg, H, 'symmetric');
1 次查看(过去 30 天)
显示 更早的评论
I am MATLAB beginner, and I got stuck because of an error.
I have no idea what it means
Error message
Not enough input arguments.
Error in Function1 (line 15)
R1 = imfilter(InputImg, H, 'symmetric');
How can I fix the errors? (my code is below)
Also, I'm working on an assignment.
If there are mistakes, please let me know/
Task: write a Matlab function that should filter an image to identify the edges and their
orientations (hortizontal, vertical, 45 degree, and 135 degree edges).
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/response of edge is below a giventhreshold
1. Input: an original image f and a threshold value T;
Output: EdgeImg and IndexImg
2. Pick the four spatial masks H, V, D45, D135 from Note 7 part 1
3. Compute R1 (hortizontal edge), R2 (vertical edge), R3 (45 degree), R4 (135 degree) for the entire image. Hint: use ‘imfilter’. For example:
R1 = imf ilter(f, H)
4. For a pixel at a location (i, j) in the image (you might want to use for loop twice):
(a)
decide in which edge direction the pixel is associated with. For example, if|R2| > Rj for all j = 1, 3, 4, then the pixel is associated with a vertical line. Hint: use [R, ind] = max [R1(i, j), R2(i, j), R3(i, j), R4(i, j)] where R stores the largest response value, ind stores the index/label that is
associated with R.
(b) If the response R ≥ T, then EdgeImg(i, j) = R; IndexImg(i, j) = ind;
(c) If the response R < T, then EdgeImg(i, j) = 0; IndexImg(i, j) = 5; (which is the non-edge index)
Test your function with an image and a threshold value and display both the edge imageand the indexed image.
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
0 个评论
采纳的回答
KSSV
2023-4-26
It looks like you are running the code/ function striaght away using hit button or F5 or by calling the function. This is not the way to call/ run a function. You need to define the inputs and then the call the function.
InputImg = imread(myimage) ; % read your image
Threshold = myval ; % define your threshold values
[EdgeImg, IndexImg] = Function1(InputImg, Threshold) ; % Now call the function
0 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!