bwtraceboundary help!
4 views (last 30 days)
Show older comments
Hi,
I am trying to trace a line in a binary image in which there are many lines.
The function is based on the MATLAB standard help page for bwtraceboundary.
The function below is working great. The contour I want is detected and MATLAB overlays a green line. However the matrix that is output (named: contour) is empty apart from coordinates of the image border!
Please please can someone tell me what I seem to be missing?
Grant
Code:
I = mat2gray(~BW4);
I = im2bw(I,0.95);
imshow(I);
[x, y] = getpts;
x=round(x);
y=round(y);
s=size(I);
for t = y:1:y+50
for u = x:1:s(2)
if I(t,u),
break;
end
end
contour = bwtraceboundary(I, [t, u], 'W', 4, inf,...
'counterclockwise');
if(~isempty(contour))
hold on;
plot(contour(:,2),contour(:,1),'g','LineWidth',2);
hold on;
plot(x, y,'gx','LineWidth',2);
else
hold on; plot(x, y,'rx','LineWidth',2);
end
end
0 Comments
Accepted Answer
Walter Roberson
on 6 Feb 2012
Using a variable named "contour" is not a good idea, as it conflicts with the name of the useful MATLAB routine "contour".
You are setting the variable "contour" inside a "for" loop. The value of "contour" at the end of the routine would be just whatever it was for the last iteration of the loop.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!