How to map RGB label map to grey label map?

Hello there,

If I have some label maps in RGB format, I want to convert them to Grey format and feed them to the networks. Is it necessary to convert the 3 channels label map to single channel one?

For the single channel map, just using mask[mask == pixel_value] = class_value can achieve it.

Is there a convenient method (like single channel map with one line code) to achieve this goal?
e.g.

mask_mapping = {
    [255,255,255] : 0,
    [255,255,0]   : 1,
    [255,0,0]     : 2,
    ...
}

Thanks in advance!

Okay, I have solve it by myself, but I don’t know whether it is the efficient one.
If you have other ideas, I will also appreciate it!

mask_mapping = {
    (255, 255, 0):   0,
    (0, 255, 255):   1,
    (255, 255, 255): 2,
}
for k in mask_mapping:
    label[(label == k).all(axis=2)] = mask_mapping[k]