You are here : matlabImage Processingbwboundaries

bwboundaries() - Image Processing

B = bwboundaries(BW) traces the exterior boundaries of objects, as well as boundaries of holes inside these objects, in the binary image BW. bwboundariesalso descends into the outermost objects (parents) and traces their children (objects completely enclosed by the parents). Returns B, a cell array of boundary pixel locations.

B = bwboundaries(BW,conn) traces the exterior boundaries of objects, where conn specifies the connectivity to use when tracing parent and child boundaries.

B = bwboundaries(BW,conn,options) traces the exterior boundaries of objects, where options is either the string 'holes' or 'noholes', specifying whether you want to include the boundaries of holes inside other objects.

[B,L]= bwboundaries(___) returns a label matrix L where objects and holes are labeled.

[B,L,N,A] = bwboundaries(___) returns N, the number of objects found, and A, an adjacency matrix.

Code Generation support: Yes.

MATLAB® Function Block support: No.


Syntax

B = bwboundaries(BW)
B = bwboundaries(BW,conn)
B = bwboundaries(BW,conn,options)
[B,L]= bwboundaries(___)
[B,L,N,A] = bwboundaries(___)


Example

%Read grayscale image into the workspace.
I = imread('rice.png');

%Convert grayscale image to binary image using local adaptive thresholding.
BW = imbinarize(I);

%Calculate boundaries of regions in image and overlay the boundaries on the image.
[B,L] = bwboundaries(BW,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
   boundary = B{k};
   plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end


Output / Return Value


Limitations


Alternatives / See Also


Reference

http://in.mathworks.com/help/images/ref/bwboundaries.html