Intersecting and non-intersecting box regions

1 次查看(过去 30 天)
Having a set of bounding box values [x y width height] , how can i find the number of bounding box that gets intersected and that do not gets intersected when plotted
From the above example, there are 5 intersecting boxes and 2 non-intersecting boxes
How can i do so with the attached bounding box values

采纳的回答

Matt J
Matt J 2021-7-10
编辑:Matt J 2021-7-10
Using rectint(), you can straightforwardly obtain a binary mask A such that A(i,j)=1 if rectangle bbx(i,:) and bbx(j,:) intersect.
load bbx
A=rectint(bbx,bbx)>0
A = 20×20 logical array
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
and therefore the number of rectangles that have an intersection another rectangle would be,
N=sum(tril(A,-1),'all')
  6 个评论
Elysi Cochin
Elysi Cochin 2021-7-12
编辑:Elysi Cochin 2021-7-12
load bbx
A = rectint(bbx,bbx)>0
Sir there are total 20 boxes
and non-intersecting box = 13, but there are more zeros, in the matrix A
So Sir, if I use A(i,j), how will i get 13?

请先登录,再进行评论。

更多回答(2 个)

Simon Chan
Simon Chan 2021-7-10
If viusal inspection is allowed, then the number can be counted by plotting the boxes in a figure:
rawdata=load('bbx.mat');
figure
for k=1:length(rawdata.bbx)
rectangle('Position',rawdata.bbx(k,:))
end
  4 个评论
Elysi Cochin
Elysi Cochin 2021-7-10
when i increase the number of rows in bbx, i get error
Matrix dimensions must agree.
Error in demo
B = B+A;
Simon Chan
Simon Chan 2021-7-10
Would you please run the following commands before the above script:
clear;
clc;
If the error happens again, would you please run the following:
size(A) % Check the dimension of Matrix A
size(B) % Check the dimension of Matrix B

请先登录,再进行评论。


KSSV
KSSV 2021-7-10
Run a loop for each box and find the intersection points. Use this to get the intersection points.
If your output is empty, it means there is no intersection.
  3 个评论
KSSV
KSSV 2021-7-10
You have origin, length and width of bounding box. So you can get four vertices of the box. You need to use four coordinates for each bounding box to get the intersection points.
Elysi Cochin
Elysi Cochin 2021-7-10
i didnt get that Sir. Please can you show me an example?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by