我有一组针对某个图像的区域(边界框),以下是示例Python代码:
im = Image.open("single.png")
pix = np.array(im)
gray = rgb2grey(pix)
thresh = threshold_otsu(gray)
bw = closing(gray > thresh, square(1))
cleared = bw.copy()
clear_border(cleared)
borders = np.logical_xor(bw, cleared)
label_image = label(borders)
for region in regionprops(label_image, ['Area', 'BoundingBox']):
#now i have bounding boxes in hand
我想做的是合并重叠的区域或bbox边缘之间的距离小于
X
。天真的方法是检查所有区域之间的距离,这具有O(n2)的复杂度。我可以写一些更聪明的东西,但我有印象这种算法已经存在了,我不想重新发明轮子。任何帮助都将不胜感激。