Newbie here! I'm working with python plus opencv and skimage packages. I've segmented an image in superpixels using:
segments = slic(image, n_segments=numSegments, sigma=1, convert2lab=True)
I can access every superpixel with:
#FOR-LOOP-1
for v in np.unique(segments):
#create a mask to access one region at the time
mask = np.ones(image.shape[:2])
mask[segments == v] = 0
#my function to calculate mean of A channel in LAB color space
A = mean_achannel(img, mask)
Now I'd like to get the coordinates associated with each superpixel's centroid, how can I do that? I tried using:
from skimage.measure import regionprops
#FOR-LOOP-2
regions = regionprops(segments)
for props in regions:
cx, cy = props.centroid # centroid coordinates
But I can't understand how to link each region in the "FOR-LOOP-2" with the right one in the "FOR-LOOP-1". How can I calculate each region centroid inside "FOR-LOOP-1"?
centers = np.append(centers, [np.mean(np.nonzero(segments == v), axis=1)])- Jimbo