www.gusucode.com > images 案例代码 matlab源码程序 > images/CalculateCentroidsOf3DObjectsExample.m

    %% Calculate Centroids of 3-D Objects
% 
%%
% Create a small sample 3-D array.
BW = cat(3, [1 1 0; 0 0 0; 1 0 0],...
            [0 1 0; 0 0 0; 0 1 0],...
            [0 1 1; 0 0 0; 0 0 1]);
%%
% Find the connected components in the array.
CC = bwconncomp(BW)
%%
% Calculate centroids of the objects in the array.
S = regionprops(CC,'Centroid')