split label matrix into cells according to their lables including boundary
조회 수: 11 (최근 30일)
이전 댓글 표시
Hi, I have a label matrix and want to split the area into individual matrix for post processing. I need the boundary accosiated with the label as well. I have tried label2idx but it does not contain the boundary (labelled as 0). Is there any easy way to do this?
댓글 수: 1
dpb
2022년 10월 4일
Attach example data of what you are starting with and what you would want the result to be; I don't know what a "label matrix" is by that description.
답변 (1개)
Sufiyan
2023년 5월 25일
You can follow the procedure shown in the below code to split the area in to individual matrix.
% sample label matrix
label_matrix = zeros(50,50);
label_matrix(10:20,10:20) = 1;
label_matrix(30:40,10:20) = 2;
label_matrix(10:20,30:40) = 3;
label_matrix(30:40,30:40) = 4;
% get the boundaries of the labeled regions
boundaries = bwboundaries(label_matrix, 'noholes');
% extract the individual regions and store them in a cell array
regions = cell(length(boundaries), 1);
for i = 1:length(boundaries)
region = boundaries{i};
x_min = min(region(:,2));
x_max = max(region(:,2));
y_min = min(region(:,1));
y_max = max(region(:,1));
region_matrix = label_matrix(y_min:y_max, x_min:x_max);
regions{i} = region_matrix;
end
Hope this helps!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!