title: How to convert 3D RGB label image (in semantic segmentation) to 2D gray image, and class indices start from 0?
body: <p>I have a rgb semantic segmentation label, if there exists 3 classes in it, and each RGB value is one of:</p>
  
  <pre><code>[255, 255, 0], [0, 255, 255], [255, 255, 255]
  </code></pre>
  
  <p>respectively, then I want to map all values in RGB file into a new 2D label image according to the dict:</p>
  
  <pre><code>{(255, 255, 0): 0, (0, 255, 255): 1, (255, 255, 255): 2}
  </code></pre>
  
  <p>after that, all values in the new gray label file is one of 0, 1 or 2.
  Is there an efficient way to solve this problem? For example <strong>broadcasting</strong> in NumPy.</p>