Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ximgproc - SLIC Segmentation - Get coordinates of label

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:

image = np.ndarray((352,1216),dtype = np.uint16) #is image where each point is assigned with a label/superpixel

for label in range(0,number_of_labels)
   superpixel[label] = np.argwhere(image == label)

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

ximgproc - SLIC Segmentation - Get coordinates of label

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:superpixel. My ineffecient code looks like the following (when using skimage.segmentation.slic):

image = np.ndarray((352,1216),dtype = np.uint16) #is image #segments is 2D array, where each point is assigned with a label/superpixel

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 label i in range(0,number_of_labels)
range(0,np.max(segments)):
 superpixel[label] = np.argwhere(image superPixel.append(np.argwhere(segments == label)
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

ximgproc - SLIC Segmentation - Get coordinates of label

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