www.gusucode.com > vision 源码程序 matlab案例代码 > vision/LabelConnectedRegionsInAnImageExample.m
%% Label Connected Regions in an Image % Copyright 2015 The MathWorks, Inc. img = logical([0 0 0 0 0 0 0 0 0 0 0 0 0; ... 0 1 1 1 1 0 0 0 0 0 0 1 0; ... 0 1 1 1 1 1 0 0 0 0 1 1 0; ... 0 1 1 1 1 1 0 0 0 1 1 1 0; ... 0 1 1 1 1 0 0 0 1 1 1 1 0; ... 0 0 0 0 0 0 0 1 1 1 1 1 0; ... 0 0 0 0 0 0 0 0 0 0 0 0 0]) hlabel = vision.ConnectedComponentLabeler; hlabel.LabelMatrixOutputPort = true; hlabel.LabelCountOutputPort = false; labeled = step(hlabel, img)