Preserve the label information when extracing boundaries from label matrix

2 vues (au cours des 30 derniers jours)
HAOYANG MI
HAOYANG MI le 19 Déc 2021
Hello, I would like to get the boundary labels when extracting boundaries from label matrix.
Right now, I understand that I can generate boundary masks from the following function:
bm = boundarymask(labelmatrix), however, the generated masks are binary, that is to say, I wouldn't know which mask correspond to what label. I am wondering if there is a way to preserve such information, so that I can know which boundary is for label 1, 2, 3..., etc.
Thanks in advance!

Réponses (2)

DGM
DGM le 20 Déc 2021
You can do something like this:
A = imread('blobs.png');
L = bwlabel(A);
B = L.*boundarymask(L); % multiply
[min(L(:)) max(L(:))] % label array has 28 blobs
ans = 1×2
0 28
[min(B(:)) max(B(:))] % boundary array also has 28 labeled blob boundaries
ans = 1×2
0 28

yanqi liu
yanqi liu le 20 Déc 2021
clc; clear all; close all;
A = imread('kobi.png');
L = superpixels(A,100);
% label id
inds = sort(unique(L(:)));
% for every label id
mask = boundarymask(L);
figure
imshow(mask)
hold on;
for i = 1:length(inds)
maski = boundarymask(L==inds(i));
% display every label by different color
[ri,ci] = find(maski);
plot(ci,ri,'.','Color',rand(1,3))
end

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by