how to visualize segmented labels in a already existing graph?

I am working on a project where I have to segment the image using multi-class segmentation (3 classes) on microscopic images.

Now let's say that I am segmenting solid, liquid and gas images (this is an example made up for asking the question because I am not allowed to discuss anything about the project :( ), I have pixel wise segmented solid, liquid and gas. But now, once I have segmented these images, I want to put the results on already existing graph. for example, if the water in images is segmented as red in color, then I want to interpret this result in already existing graph with the red color as an indicator(I have added images as example), same goes for blue color as solid.

Can anyone please help me how to do this? I am using u-net architecture for semantic segmentation. This is my first question, although I have tried to explain the question to best of my ability, please let me know if more information is needed to help me answer this question. I initially asked this question on stackoverflow (https://stackoverflow.com/questions/71341512/how-to-visualize-segmented-labels-in-a-already-existing-graph) but then I was advised to post it here. Thank you in advance. [

Topic semantic-segmentation interpretation multiclass-classification python

Category Data Science


You can simply use the pixel predictions from your network, go through all of your classes, and give each pixel that belongs to a specific class the corresponding color. You can take some inspiration from the following labelVisualize function from a unet repository:

def labelVisualize(num_class, color_dict, img):
    img = img[:, :, 0] if len(img.shape) == 3 else img
    img_out = np.zeros(img.shape + (3,))
    for i in range(num_class):
        img_out[img == i, :] = color_dict[i]
    return img_out / 255

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.