此方法将label[0...N]矩阵对应成随机色彩,便于观察。
如有label为0,则强制对应成黑色。
function [] = showLabels( L )
unilabels = unique(L);
NUM = length(unilabels);
compactL = zeros(size(L));
for i=1:NUM
compactL(L==unilabels(i)) = i;
end
h = hsv(NUM);
r = randperm(NUM);
cmap = h(r,:);
if(unilabels(1)==0)
cmap(1,:) = [0 0 0];
end
figure; imshow(reshape(cmap(compactL,:),size(L,1),size(L,2),3));
end
例:
>> labels = magic(3)
labels =
8 1 6
3 5 7
4 9 2
>> showLabels(imresize(labels,100,'nearest'));
如有label为0,则强制对应成黑色。
function [] = showLabels( L )
unilabels = unique(L);
NUM = length(unilabels);
compactL = zeros(size(L));
for i=1:NUM
compactL(L==unilabels(i)) = i;
end
h = hsv(NUM);
r = randperm(NUM);
cmap = h(r,:);
if(unilabels(1)==0)
cmap(1,:) = [0 0 0];
end
figure; imshow(reshape(cmap(compactL,:),size(L,1),size(L,2),3));
end
例:
>> labels = magic(3)
labels =
8 1 6
3 5 7
4 9 2
>> showLabels(imresize(labels,100,'nearest'));
Aucun commentaire:
Enregistrer un commentaire