Intersecting and non-intersecting box regions
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (2)
Simon Chan
il 10 Lug 2021
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 Commenti
Elysi Cochin
il 10 Lug 2021
Simon Chan
il 10 Lug 2021
The following method may only appropriate for the case where multiples of x and y are both integers.
In this case, the x and y coordinates are in 0.5 format and hence I multiply by 2.
Assign a matrix B which is large enough to cover all the boxes.
Add 1 to the region of each box and the overlapping boxes will have value inside its box > 1, which indicates intersecting boxes.
data=2*rawdata.bbx; % Make all coordinates to integers
B = zeros(1000,1000); % Matrix to accumulate all boxes
for k=1:length(rawdata.bbx)
A=zeros(1000,1000);
A(data(k,2):data(k,2)+data(k,4),data(k,1):data(k,1)+data(k,3))=1;
B = B+A;
end
% Calculating all the values inside each box after accumulation
for k =1:length(rawdata.bbx)
finalarea(k,1)=sum(sum(B(data(k,2):data(k,2)+data(k,4),data(k,1):data(k,1)+data(k,3))));
end
area=(data(:,3)+1).*(data(:,4)+1); % Original area of each box
Intersect_Number = sum(finalarea-area>0)
Elysi Cochin
il 10 Lug 2021
Simon Chan
il 10 Lug 2021
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
il 10 Lug 2021
0 voti
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 Commenti
Elysi Cochin
il 10 Lug 2021
KSSV
il 10 Lug 2021
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
il 10 Lug 2021
Categorie
Scopri di più su Image Arithmetic in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!