@@ -0,0 +1,967 @@
+import PIL%0Aimport PIL.Image%0Aimport numpy as np%0Aimport os%0Adef viz_segmentation_label(label, color_mapper=None, saveto=None):%0A    if color_mapper is None:%0A        # Default color mapper%0A        color_mapper = %5B%5B0,0,0%5D,%0A                        %5B48,126,199%5D,%0A                        %5B115,173,33%5D,%0A                        %5B255,79,64%5D,%0A                        %5D%0A    # Map each pixel label to a color%0A    label_viz = np.zeros((label.shape%5B0%5D,label.shape%5B1%5D,3), dtype=np.uint8)%0A    uids = np.unique(label)%0A    for uid in uids:%0A        label_viz%5Blabel==uid%5D = color_mapper%5Buid%5D%0A%0A    # Convert to PIL image%0A    label_viz = PIL.Image.fromarray(label_viz)%0A%0A    if saveto is not None:%0A        # Create necessary file structure%0A        pardir = os.path.dirname(saveto)%0A        if pardir.strip() != %22%22: # ensure pardir is not an empty string%0A            if not os.path.exists(pardir):%0A                os.makedirs(pardir)%0A        label_viz.save(saveto, %22JPEG%22)%0A%0A    return label_viz%0A

Add viz_segmentation_label()