relabel matrix accroding to another label mapping
2 次查看(过去 30 天)
显示 更早的评论
I have a label matrix for an image, for example:
map = [1 1 2 5 6; 1 2 2 5 6; 1 2 3 4 5; 2 3 4 4 5]
I have another label mapping vector, to map a label in map to another label. For example, in map, there are 6 labels, so the label mapping vector is [6x1]:
label = [0 3 0 9 10 3]
meaning, label 1 and 3 in map is remapped to 0; label 2 and 6 is remapped to 3; label 4 and 5 in map is remapped to 9 and 10 respectively.
How can I replace labels in map with new labels?
0 个评论
回答(1 个)
Image Analyst
2014-11-18
Use intlut():
% Create sample data.
map = [1 1 2 5 6; 1 2 2 5 6; 1 2 3 4 5; 2 3 4 4 5]
label = [0 3 0 9 10 3]
% Create 256 element look up table.
lut = uint8([label, zeros(1, 256-length(label))]);
% Use intlut to transform the image.
output = intlut(uint8(map), lut)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!