我有一些图像的一组区域(边界框),例如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(n 2 ) 复杂性。我可以写一些更聪明的东西,但我的印象是这种算法已经存在,我不想重新发明轮子。任何帮助表示赞赏。