I am MATLAB beginner, and I got stuck because of some error.
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Garrett Fullerton
2023 年 4 月 26 日
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 件のコメント
Stephen23
2023 年 4 月 26 日
"I have no idea what it means"
How are you calling the function? How many input arguments did you provide when you called it?
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!