MATLAB: Bwboundaries returning empty cell array

bwboundariesimage processingImage Processing Toolbox

The attached binary array should have two regions, one small one big. When I run:
[B L] = bwboundaries(BW);
B has one full cell corresponding to the small region, and one empty cell i assume should be the large region. Further, the L array correctly sets the larger region values to 2, so I know the large region is being detected. So why is that B cell empty?

Best Answer

There are either 1 8-connected region or 4 four connected regions:
s = load('bin_array.mat')
BW = s.BW;
imshow(BW);
[boundaries, L] = bwboundaries(BW, 8);
fprintf('With 8-connected, there are %d boundaries.\n', length(boundaries));
[boundaries, L] = bwboundaries(BW, 4);
fprintf('With 4-connected, there are %d boundaries.\n', length(boundaries));
BW: [493×160 double]
With 8-connected, there are 1 boundaries.
With 4-connected, there are 2 boundaries.
You must not be using 4 as the second argument. If you use nothing, or 8, you will have L be 1 everywhere, not 2 like you said. The max value of L will always match the number of regions. So your problem cannot be reproduced, and always gives the correct answer. If you don't think so, then post your code.