【发布时间】:2021-03-20 04:15:29
【问题描述】:
我正在尝试对花生形状的分布进行斑点检测 - 典型示例见下图:
我想找到这两个 blob 的质心,但我不确定哪种计算机视觉方法或算法最适合解决这个问题。理想情况下,解决方案应该是轻量级的,因为我需要处理许多这样的 blob。到目前为止,我已经尝试使用 skimage.feature.blob_doh 来获取 blob 中心和半径,并找到该 blob 的加权平均像素,但由于 blob_doh 与 blob 的连接性质(即只返回一个 blob):
blobbing代码如下:
def get_blobs(image, num_blobs):
img = image
img = cv.normalize(img, None, 0.0, 1.0, cv.NORM_MINMAX)
img = img.astype(float)
blobs = blob_doh(img)
ys = np.array([x[0] for x in blobs])
xs = np.array([x[1] for x in blobs])
rs = np.array([x[2] for x in blobs])
sort_args = np.argsort(rs)
xs, ys, rs = xs[sort_args], ys[sort_args], rs[sort_args]
if len(ys) < num_glints:
diff = num_blobs - len(ys)
ys = np.concatenate((ys, np.zeros((diff)))).astype(float)
xs = np.concatenate((xs, np.zeros((diff)))).astype(float)
rs = np.concatenate((rs, np.zeros((diff)))).astype(float)
num_blobs = len(ys)
xs, ys, rs = xs[0:num_blobs], ys[0:num_blobs], rs[0:num_blobs]
return xs, ys, rs
我也不想对图像进行二值化,因为我发现质心是这样的:
def find_centroid(xs, ys, weights):
sum_w = np.sum(weights)
sum_x = np.sum(np.multiply(xs, weights))
sum_y = np.sum(np.multiply(ys, weights))
cx = sum_x / sum_w
cy = sum_y / sum_w
return [cx, cy]
(换句话说,斑点中的所有像素都对质心有贡献)。 非常感谢!
【问题讨论】:
-
不确定您是否尝试过,但您可能会发现,将一些形态学操作作为预处理步骤(侵蚀或打开)简单地应用于图像可能有助于拆分这些斑点。
标签: python opencv scipy computer-vision