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

编程入门 行业动态 更新时间:2024-10-07 23:26:14
多个较小的框中构建外部边界框(Building an outer bounding box from multiple smaller boxes)

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

例如

到目前为止,我有一个叫做rects的矩形向量。

overlaps = rectint(rects, rects);

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

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

然后找到重叠的位置

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

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

任何有关我如何进行的建议将不胜感激。

谢谢

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.

e.g.

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;

Then find the locations of the overlaps

[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.

Thanks

最满意答案

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

% 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',':');

在此处输入图像描述

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',':');

enter image description here

更多推荐

本文发布于:2023-07-09 10:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   较小   边界   框中   Building

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!