segments = slic(image, n_segments=numSegments, sigma=1, convert2lab=True)
现在我想获得与每个超像素的质心相关的坐标,我该怎么做?
答案 0 :(得分:2)
尝试查看skimage.measure.regionprops
:
from skimage.measure import regionprops
regions = regionprops(segments)
for props in regions:
cx, cy = props.centroid # centroid coordinates
答案 1 :(得分:0)
您可以通过按以下方式按类平均每个坐标来轻松完成:
import numpy as np
import cv2
slic = cv2.ximgproc.createSuperpixelSLIC(image, n_segments=numSegments, sigma=1, convert2lab=True))
num_slic = slic.getNumberOfSuperpixels()
for cls_lbl in range(num_slic):
fst_cls = np.argwhere(lbls==cls_lbl)
x, y = fst_cls[:, 0], fst_cls[:, 1]
c = (x.mean(), y.mean())
print(f'Class {cls_lbl} centroid coordinates: ({c[0]:.1f}, {c[1]:.1f})')
干杯