bwtraceboundary
Trace boundary pixels of a binary object.
📝Syntax
B = bwtraceboundary(BW, p)
B = bwtraceboundary(BW, p, fstep, conn)
B = bwtraceboundary(BW, p, fstep, conn, m)
📥Input Arguments
Parameter Description
BW Input binary image. Nonzero values are treated as true.
p Boundary start point [row column].
fstep First search direction.
conn Connectivity, either 4 or 8.
m Maximum number of boundary points to return.
📤Output Arguments
Parameter Description
B Boundary coordinates as an N-by-2 [row column] matrix.
📄Description

Trace boundary pixels of the binary object containing the start point p = [row column]. Supported connectivities are 4 and 8. The first search direction can be N, NE, E, SE, S, SW, W, or NW for 8-connectivity, and N, E, S, or W for 4-connectivity.

💡Examples
Trace a square boundary
BW=false(64,64); BW(16:48,16:48)=true;
B=bwtraceboundary(BW, [16 16], 'E', 8);
figure; imagesc(BW); hold on; plot(B(:,2), B(:,1), 'r.'); title('Traced boundary');
Example illustration
🔗See Also
bwboundariesbwperim
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub