www.gusucode.com > images 案例代码 matlab源码程序 > images/CalculatePixelIndexListForSmallLabelMatrixExample.m
%% Calculate Pixel Index List for Small Label Matrix % %% % Create a small sample matrix containing three regions. BW = logical([1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 0 0]); %% % Create a label matrix from this sample image. L = bwlabel(BW) %% % Get a linear index list of all the pixels in each region. The function % returns a cell array with an element for each region it finds in the % label matrix. pixelIndexList = label2idx(L) %% % Examine one of the pixel index lists returned. For example, look at the % second cell in the returned cell array. It contains the linear indices % for all the pixels in the region labeled "2". The upper left % corner of the region is pixel BW(2,5), which is the 34th pixel in % linear indexing. pixelIndexList{2}