find overlapping rectangles algorithm in matlab

Hi
Is there an algorithm which can help in finding overlapping rectangles.
I use connected components for segmentation and hecne get a number of overlapping and independent rectangles. My aim is to remove the overlapping rectangles by checking the coordinates . If my current rectangle falls within the coordinate of outer rectangle then it will consider the outer rectangle and if my rectangle is bigger then it is considered.
i want to retain all bigger rectangles around a word and eliminate smaller rectangles.
is there a code for finding overlapping rectangles?
groupRect = [lv tv new_width new_height];
groupRects(groupRectsCt,:)=groupRect;
groupRectsCt=groupRectsCt+1;
end
id = id+1;
end
% display the segmented image
figure, imshow(SearchedImg);
for i=1:groupRectsCt-1
rectangle('Position', groupRects(i,:), 'EdgeColor', 'r');
end
%%%find and remove overlaping regions
for i=1:groupRectsCt-1
if(currentRect(1,1)>=cRect(1,1) & currentRect(1,1)+currentRect(1,3)<=cRect(1,1)+cRect(1,3))
flag =1; break;
end
if(currentRect(1,1)<=cRect(1,1) & currentRect(1,1)+currentRect(1,3)>=cRect(1,1)+cRect(1,3))
candiRect(j,:) = currentRect; flag =1; break;
end
if(flag) continue; end
candiRect(candiCt,:) = currentRect;
end

4 Comments

%%previous segmentation code continued groupRect = [lv tv new_width new_height]; groupRects(groupRectsCt,:)=groupRect; groupRectsCt=groupRectsCt+1;
end
id = id+1;
end
% display the extraction
figure, imshow(SearchedImg);
for i=1:groupRectsCt-1
rectangle('Position', groupRects(i,:), 'EdgeColor', 'b');
end
%%remove overlapping part
for i=1:groupRectsCt-1
%%%how to sort rectangles?
currentRect = groupRects(1,i), :);
flag =0;
if(currentRect(1,1)>=cRect(1,1) & currentRect(1,1)+currentRect(1,3)<=cRect(1,1)+cRect(1,3))
flag =1; break;
end
if(currentRect(1,1)<=cRect(1,1) & currentRect(1,1)+currentRect(1,3)>=cRect(1,1)+cRect(1,3))
candiRect(j,:) = currentRect; flag =1; break;
end
end
if(flag) continue; end
candiRect = currentRect;
end
this is code what i wrote.. but i think the condition of sorting the rectangles is wrong?
ie : how to sort rectangles? currentRect = groupRects(1,i), :);
could you advise?
Thanks
My advice is to attach an image or diagram so we can visualize what you're talking about.
A binary or labeled image cannot have overlapping regions. If regions in a binary image overlap, then they are considered the same region, not different ones. If regions in a labeled image overlap, then the "top" one overlaps/covers the "underneath" one and so not all of the underneath one will be used in measurements. So I really don't know what you're talking about without a diagram or image to help explain it.
Why do you need to find them? Something (I don't know what) created the rectangles, so you just need to go back to the function that made them in the first place to "find" them.
yes i hve attached a sample image..
if you see the image and look at word opportunity: there are multiple overlapping rectagnles 1 : one rectangle coverig opp 2: other one covering oppor 3. one on opportu and other on complte word opportunity.
so since i have a bigger rectangle covering entire word opportunity: i want to eliminate all rectangles falling within its co-ordinates.
I hope my question is clear now
my required segmentation output is the green color box

Sign in to comment.

Answers (0)

Asked:

on 13 Jul 2015

Edited:

on 13 Jul 2015

Community Treasure Hunt

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

Start Hunting!