Discussions>Generating binary masks for each object present in a groundtruth mask>

Generating binary masks for each object present in a groundtruth mask

I have ground-truth masks containing all instances of objects present in a single image. While exploring UNET, I realized that I need to create binary masks for each instance of the object in each ground truth image to create weight maps. Weight maps are used in the loss function to separate touching objects.

Could you please give some directions to compute the masks for each instance?

2 votesAS2.00
1 Answers
JW297.00
1

There is a small python code, which extracts all unique colors, then separates the colored mask into binary masks for each instance-color.

import cv2
import numpy as np

mask = cv2.imread(mask_path)
# Let's find unique colors of the mask
unique_colors = np.unique(mask.reshape(-1, mask.shape[2]), axis=0)
masks = np.zeros(mask.shape)

for color in unique_colors:
    object_mask = np.where(mask == color, 1, 0)
    object_mask = np.prod(object_mask, axis=-1)
    masks = np.dstack([object_mask, masks])

Also, this question is duplicate and you can find your answer in the following discussion
"Get binary mask for every object in instance segmentation"

Reply
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?