从多个较小的框中构建外部边界框 [英] Building an outer bounding box from multiple smaller boxes

查看:174
本文介绍了从多个较小的框中构建外部边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在所有重叠的较小边界框周围绘制一个外边界框。整个图像中可能有许多这样的区域。

I am trying to draw an outer bounding box, around all smaller bounding boxes that are overlapping. There may be many of these regions within the entire image.

例如。

到目前为止,我的矩形向量称为rects。

So far I have my vector of rectangles called rects.

overlaps = rectint(rects, rects); 

我检查彼此重叠的地方,因为它会与自身进行比较,我将对角线移除如下:

Where I check of overlaps with each other, and because it will compare with itself I remove the diagonal as follows:

overlaps(logical(eye(size(overlaps)))) = 0;

然后找到重叠的位置

[r,c] = find(overlaps > 0);

但是,我不知道如何处理这个因为它不是一个简单的双向映射返回方形矩阵,因为该区域可能存在多个重叠。

However, I am not sure how to deal with this as it is not a simple bi directional mapping in the square matrix returned, as there can be multiple overlaps in the area.

我们将非常感谢您对我如何进行的任何建议。

Any suggestions on how I can proceed would be greatly appreciated.

谢谢

推荐答案

这里有一些随机矩形的例子:

here's and example with some random rectangles:

% Generate fake data, 3 rects with format [x,y,w,h]:
rects=20+randi(60,3,4);

% plot the rects :
for n=1:size(rects,1) 
    rectangle('Position',rects(n,:));
end

% get min max
xmin=min(rects(:,1));
ymin=min(rects(:,2));
xmax=max(rects(:,1)+rects(:,3));
ymax=max(rects(:,2)+rects(:,4));

% define outer rect:
outer_rect=[xmin ymin xmax-xmin ymax-ymin];

hold on
rectangle('Position',outer_rect,'EdgeColor','r','LineStyle',':');

这篇关于从多个较小的框中构建外部边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆