Question

Assuming that you have the result of a superpixeling algorithm such as SLIC Superpixel Algorithms

segments_slic = slic(img, n_segments=250, compactness=10, sigma=1)

How can you display the image as being colored differently for each superpixel with a preset color (say, you know beforehand which color coresponds to each superpixel, as in a semantic labelling problem.

I need something similar to

imshow(mark_boundaries(img, segments_slic))

but instead of just marking the boundaries, I need semantic segmentation with the labels that I work with

Was it helpful?

Solution

If you know which value you'd like to assign to a specific position, say at (i, j), make a copy of the labels

new_labels = labels.copy()

Then proceed to "rename" the labels:

new_labels[labels == labels[i, j]] = new_label_value
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top