[B,L] =bwboundaries(...)
B是一个 P x 1的数组,其中P代表连通体的个数.B内每一行是一个 Q x 2的矩阵,Q内每一行表示连通体的边界像素的位置坐标(第一列是纵坐标Y,第二列是横坐标X),Q为边界像素的个数.
附:引用原文
bwboundaries returnsB, a P-by-1 cell array, where P isthe number of objects and holes. Each cell in the cell arraycontains a Q-by-2 matrix. Each row in the matrix contains the rowand column coordinates of a boundary pixel. Q is the number ofboundary pixels for the corresponding region.
I = imread('rice.png');%读入图像
BW = im2bw(I, graythresh(I));%转换成2进制图像
[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%整个循环表示的是描边