ximgproc - SLIC Segmentation - Get coordinates of superpixel

asked 2020-04-17 06:26:35 -0500

Horst gravatar image

updated 2020-04-17 07:04:45 -0500

Hey guys,

right now I'm using the ximgproc module to apply the SLIC-algorithm to an image. So far, this works very well. I Problem is the following: I need to have an array, which stores for each superpixel all corresponding points in the image. This can be interpreted as:

Superpixel = [] #array which contains all superpixels/labels
Superpixel[0] =[] #Superpixel with label 0 contains an array of points

How is this efficiently done? Right now I'm using e.g. np.argwhere to find all coordinates with the specific label in the image and write it into the corresponding superpixel. My ineffecient code looks like the following (when using skimage.segmentation.slic):

#segments is 2D array, where each point contains label-value (in this case 0-4000)
segments = slic(self.color, n_segments = 4000, sigma = 1)
superPixel = []

#iterate through all labels and write their coordinates into array
for i in range(0,np.max(segments)):
   superPixel.append(np.argwhere(segments == i))

I think it can be seen, that this is a huge amount of calculation time. Is there any better way, to get all coordinates which are assigned to a specific superpixel?

Best and looking forward for some hints

edit retag flag offensive close merge delete