explanation on a bwtraceboundary code
1 view (last 30 days)
Show older comments
I have this code and I can't understand what does the 55 on the 4th row. Can anyone explain me?
if true
BW = imread('blobs.png');
imshow(BW);
s=size(BW);
*for row = 2:55:s(1)*
for col=1:s(2)
if BW(row,col),
break;
end
end
contour = bwtraceboundary(BW, [row, col], 'W', 8, 50,...
'counterclockwise');
if(~isempty(contour))
hold on;
plot(contour(:,2),contour(:,1),'g','LineWidth',2);
hold on;
plot(col, row,'gx','LineWidth',2);
else
hold on; plot(col, row,'rx','LineWidth',2);
end
end
end
0 Comments
Answers (1)
Christiaan
on 23 Mar 2015
Dear Rafaela,
In your code an image is imported, with the size (s1) by (s2) pixels. The first value corresponds to the amount of horizontal pixels. The second value corresponds to the amount of vertical pixels.
In the first for loop, an array is generated, where 8 rows are selected (2, 25, 112 .. etc). In the second loop each column is selected (1, 2, 3, ...) . Therefore by nesting these for loops, a grid is generated, where a calculation can be performed, where the knots of these gridlines can be used for calculation.
In this MATLAB code, the if loop checks if the point on that knot is zero (white). I hope this has helped you.
As a hint: On this Mathworks website, a short tutorial can be found to trace an object in an binary image.
Kind regards, Christiaan
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!