bwboundaries
Find boundary pixels of binary regions.
📝Syntax
B = bwboundaries(BW)
B = bwboundaries(BW, conn)
[B, L, n] = bwboundaries(BW, conn, option)
📥Input Arguments
Parameter Description
BW Input binary image. Nonzero values are treated as true.
conn Connectivity, either 4 or 8.
option Boundary option: 'holes' or 'noholes'.
📤Output Arguments
Parameter Description
B Cell array of boundary coordinate matrices.
L Label matrix for foreground components.
n Number of foreground components.
📄Description

Find perimeter coordinates of connected binary regions. Supported connectivities are 4 and 8. The option 'holes' appends boundaries of filled holes.

💡Examples
Display boundaries of binary regions
BW=false(64,64); BW(10:28,10:30)=true; BW(36:54,38:56)=true;
B=bwboundaries(BW);
figure; imagesc(BW); hold on;
for k=1:length(B), plot(B{k}(:,2), B{k}(:,1), 'r.'); end
title('Boundaries');
Example illustration
🔗See Also
bwtraceboundarybwperimbwlabel
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub