www.gusucode.com > images 案例代码 matlab源码程序 > images/ImpactOfConnectivityOnClearingTheBorderExample.m
%% Impact of Connectivity on Clearing the Border % %% % Create a simple binary image. BW = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; %% % Clear pixels on the border of the image using 4-connectivity. Note that % |imclearborder| does not clear the pixel at (5,2) because, with % 4-connectivity, it is not considered connected to the border pixel at % (4,1). BWc1 = imclearborder(BW,4) %% % Now clear pixels on the border of the image using 8-connectivity. % |imclearborder| clears the pixel at (5,2) because, with 8-connectivity, % it is considered connected to the border pixel (4,1). BWc2 = imclearborder(BW,8)