relabel matrix accroding to another label mapping

3 views (last 30 days)
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?

Answers (1)

Image Analyst
Image Analyst on 18 Nov 2014
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)

Community Treasure Hunt

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

Start Hunting!