当前位置:网站首页>Matlab label2idx function (convert the label matrix into a cell array with linear index)

Matlab label2idx function (convert the label matrix into a cell array with linear index)

2022-07-05 11:58:00 **inevitable**

grammar

pixelIndexList = label2idx(L)

explain

pixelIndexList = label2idx(L)
% The label matrix L The described area is converted to a linear index pixelIndexList.

Example

Calculate the pixel index list of the small label matrix

% Create a small sample matrix with three areas 
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)

 Insert picture description here

% Get the linear index list of all pixels in each region 
% This function returns an array of cells , The array has elements of each region found in the label matrix 
pixelIndexList = label2idx(L)

 Insert picture description here

% Check one of the returned pixel index lists 
% for example , View the second cell in the returned cell array 
% It contains information marked as “ 2” Linear index of all pixels in the region of 
% The upper left corner of this area is pixels BW(2,5), It is the th in the linear index 34 Pixel 
pixelIndexList{2}

 Insert picture description here

Input parameters

L : Label matrix
Label matrix , An array of numbers specified as any dimension .
data type :single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Output parameters

pixelIndexList : Linear index of pixels in the region
Linear index of pixels in the region , With 1×n Cell array returns . Every element of the output pixelIndexList {n} It's a vector , It includes L All linear indexes in , among L be equal to n.

原网站

版权声明
本文为[**inevitable**]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140533367356.html