[新手!我正在使用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”内部的每个区域质心?
可以在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_intensity