Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Overlapping Bounding Boxes Problem
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Khalid Iqbal

Posts: 33
Registered: 12/23/09
Overlapping Bounding Boxes Problem
Posted: May 9, 2013 4:28 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Dear Friends
I am trying to draw rectangles using bounding boxes coordinates which should not overlap. I am not getting the required output. I want to draw different rectangles after removing their intersecting aspect. Please reply, it is very urgent.

Matlab Code:
recBox contains information [x,y,width,height]
recBox=[1 5 3 2;3 4 2 4;1 10 3 2;2 9 3 2;7 5 5 4;8 6 3 2];
figure(1);
for n=1:size(recBox,1)
rectangle('Position',recBox(n,1:4),'EdgeColor','g','LineWidth',2);
pause(0.5);
end
--------------------------------------------------------------------
for j=1:size(recBox,1)-1
for k=j:size(recBox,1)
box = intersectBoxes(recBox(j,:), recBox(k,:));
recBox(j,1)=box(1);
recBox(j,2)=box(2);
recBox(j,3)=box(3);
recBox(j,4)=box(4);
end
end
---------------------------------------------------------------------------
function box = intersectBoxes(box1, box2)
%INTERSECTBOXES Intersection of two bounding boxes
%% RES = intersectBoxes(BOX1, BOX2)
%% Example:
% box1 = [5 20 5 30];
% box2 = [0 15 0 15];
% intersectBoxes(box1, box2)
% ans = 5 15 5 15
% See also
% boxes2d, drawBox, mergeBoxes
% unify sizes of data
if size(box1,1) == 1
box1 = repmat(box1, size(box2,1), 1);
elseif size(box2, 1) == 1
box2 = repmat(box2, size(box1,1), 1);
elseif size(box1,1) ~= size(box2,1)
error('Bad size for inputs');
end

% compute extreme coords
mini = min(box1(:,[2 4]), box2(:,[2 4]));
maxi = max(box1(:,[1 3]), box2(:,[1 3]));

% concatenate result into a new box structure
box = [maxi(:,1) mini(:,1) maxi(:,2) mini(:,2)];
--------------------------------------------------------------------------
recBoxx=[];recBoxx=unique(recBox,'rows');
for n=1:size(recBoxx,1)
rectangle('Position',recBoxx(n,1:4),'EdgeColor','r','LineWidth',2);
pause(0.5);
end
hold off;
------------------------------------------------------------------------
I am in urgency and need your help.

Thanks in advance

Khalid



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.