Effacer les filtres
Effacer les filtres

I am MATLAB beginner, and I got stuck because of some error.

3 vues (au cours des 30 derniers jours)
Yojp21
Yojp21 le 26 Avr 2023
Commenté : Stephen23 le 26 Avr 2023
I am MATLAB beginner, and I got stuck because of some error.
Error: File: Function1.m Line: 31 Column: 8 (which is very bottom like If R > = Threshold)
Unsupported use of the '=' operator. To compare values for equality, use '=='. To specify name-value arguments, check that name is a
valid identifier with no surrounding quotes.
Also, the End line got an error, too
Line 34: The End operator must be used within an array index expression
How can I fix the errors?
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=zero(size(InputImg));
IndexImg=len*ones(size(InpuImg));
%Now, loop applied through the pixels at edge using for
for k=1:s(Intlmg,1)
for m =1:s(Intlmg,2)
end
EdgeImg(IndxImg==len)=0;
figure;
subplot(1,2,1,0);
show(EdgeImg,img);
subplot(1,2,2,0);
show(IndexeImg,img);
end
[R,jip] = maximize([R1(k,m),R2(k,m),R3(k,m),R4(k,m)
If R > = Threshold
EdgeImg(k,m)=R;
IndexImg(k,m)=jip;
end

Réponse acceptée

Garrett Fullerton
Garrett Fullerton le 26 Avr 2023
Hey! A greater than/equal to comparison in MATLAB is done using the ">=" symbol. Your code has a space in between the ">" and "=" symbols, and MATLAB is returning an error because it's interpreting the two symbols separately. I would try removing the space and see if that solves your error.
If R >= Threshold
EdgeImg(k,m)=R;
IndexImg(k,m)=jip;
end
  3 commentaires
Yojp21
Yojp21 le 26 Avr 2023
Thank you for the quick answer and I fixed my code, but, unfortunatelly I got other error.
I have no idea what it means
Error message
Not enough input arguments.
Error in Function1 (line 15)
R1 = imfilter(InputImg, H, 'symmetric');
Here is my updated 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
Stephen23
Stephen23 le 26 Avr 2023
"I have no idea what it means"
How are you calling the function? How many input arguments did you provide when you called it?

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by