How to colour (fill) mask annotations with different colours
I am working on an instance segmentation task and I have generated annotations for my mask. I currently have a for loop that loops through all the annotations, and draws them on a blank (i.e numpy.zeros((image.shape))) canvas, whereby in the first loop, the mask (with the annotation which has values = (28, 230, 255)) looks like this
And in the second loop the mask (with new annotations but the same value) looks like this.
I am trying to colour (or "fill in" not sure what the right terminology is) each annotation with a different colour (like the example image I show below). I initially tried to do this
import numpy as np
import skimage
mask_array = np.zeros((800, 1200, 3))
for annotation in annotations:
# draw the annotation on the mask
mask_array = annotation.value.draw(canvas=mask_array, thickness=5)
# trying to fill the annotation with a different colour
mask_array = skimage.morphology.label(mask_array)
that is I tried using skimage's label function. However, the problem here is that it assigns different values to each non-connected annotation (i.e the annotation in the first image is different from the annotation in the second image, but the annotation in the second image are all a single (non-connected) annotation. The label function treats them as different objects rather than the same object).
Any help on how to approach or solve this will be much appreciated!! Thanks!
I included an example of what I am trying to achieve. 


Comments
Post a Comment