# Intersecting and non-intersecting box regions

조회 수: 8(최근 30일)
Elysi Cochin 2021년 7월 10일
댓글: Matt J 2021년 7월 12일
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 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.
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표시 이전 댓글 수: 5숨기기 이전 댓글 수: 5
Matt J 2021년 7월 12일
>> nnz(sum(A,1)==1)
ans =
13

댓글을 달려면 로그인하십시오.

### 추가 답변(2개)

Simon Chan 2021년 7월 10일
If viusal inspection is allowed, then the number can be counted by plotting the boxes in a figure:
figure
for k=1:length(rawdata.bbx)
rectangle('Position',rawdata.bbx(k,:))
end
##### 댓글 수: 4표시 이전 댓글 수: 3숨기기 이전 댓글 수: 3
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 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표시 이전 댓글 수: 2숨기기 이전 댓글 수: 2
Elysi Cochin 2021년 7월 10일
i didnt get that Sir. Please can you show me an example?

댓글을 달려면 로그인하십시오.

### 범주

Find more on Multidimensional Arrays in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by