新手来了!我正在使用python加上opencv和skimage包。我已经用超像素分割了一幅图像:
segments = slic(image, n_segments=numSegments, sigma=1, convert2lab=True)#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) 现在我想得到与每个超像素的质心相关的坐标,我该怎么做呢?我尝试使用:
from skimage.measure import regionprops
#FOR-LOOP-2
regions = regionprops(segments)
for props in regions:
cx, cy = props.centroid # centroid coordinates但是我不能理解如何将"FOR-LOOP-2“中的每个区域与"FOR-LOOP-1”中的正确区域联系起来。如何计算"FOR-LOOP-1“内部的每个区域质心?
发布于 2020-04-07 14:10:19
所有需要的值都可以在for-loop-2中使用regionprops找到:
from skimage.measure import regionprops
#FOR-LOOP-2
regions = regionprops(segments,
intensity_image=img[..., 1])
for props in regions:
cx, cy = props.centroid # centroid coordinates
v = props.label # value of label
mean_a = props.mean_intensityhttps://stackoverflow.com/questions/49983999
复制相似问题