ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Combining Annotation Objects
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndyColmes

USA
351 Posts

Posted - Aug 05 2014 :  10:48:23  Show Profile  Reply
I have an application that automatically create a lot of small rectangle objects on an image with ImageEn. I am looking for a way to be able to be able to combine the rectangles based on how close they are together with some kind of tolerance I guess to make them into a bigger rectangle. For example, if there are 4 rectangles very close to each other or sometimes even overlapping, I would like to be able to make them into 1 rectangle using the furthest coordinates from the 4 rectangles to create that 1 rectangle.

How would I do this?

Thanks in advance.

Andy

xequte

39053 Posts

Posted - Aug 05 2014 :  19:39:14  Show Profile  Reply
Hi Andy

Are you using a TImageEnVect, with the rectangles being vect objects?

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Aug 06 2014 :  11:28:51  Show Profile  Reply
Hi Nigel,

Yes, I am using TImageVect with rectangles as vect objects. Is this good?

Thanks Nigel.

Andy
Go to Top of Page

xequte

39053 Posts

Posted - Aug 06 2014 :  18:45:05  Show Profile  Reply
Hi Andy

OK, it's not really an ImageEn question, but rather a general programming issue, so you might get better advice from a wider programming audience (say stackoverflow.com).

But in short, you would iterate through all the rectangle objects, for each count the number of objects that are "close" (using whatever overlap function suits) and if the close object count >=4 then remove the objects and create a new object of a size of the outermost bounds of the removed objects. Then iterate through the objects again, repeating until a complete iteration does not generate any new rectangles.

The process itself would not be the complex, with the only real logic going into the "find close objects" routine. That would involve a sub function that iterates through all objects and finds the first object that is within the bounds + threshold of our source object. Of course, because you will call this function repeatedly you would need to have an exclusion list (those already found) or better, commence iteration from the index of the last found. Call this sub-function repeatedly until it does not return any new rectangles.

Anyway, that's just off the top of my head. As mentioned, you may get better advice from some guru on stackoverflow.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Aug 06 2014 :  22:37:51  Show Profile  Reply
Thanks Nigel. I will do that and maybe report back in case other users are looking for something similar.
Go to Top of Page

rmklever

Norway
52 Posts

Posted - Aug 08 2014 :  15:23:43  Show Profile  Reply
Hi Andy,

You can expand all your rectangles with the tollerance and then iterate all recangles with IntersectRect. If they intersect you just combine them.

This is one way of doing it.

Roy M Klever
Klever on Delphi - www.rmklever.com
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Aug 09 2014 :  22:29:24  Show Profile  Reply
Hi Roy,

That's an idea. I will give it a shot. Thanks very much, Roy.

Andy
Go to Top of Page

xequte

39053 Posts

Posted - Aug 10 2014 :  16:00:36  Show Profile  Reply
Yes, IntersectRect is good if you are looking for rects that overlap. You could use InflateRect (before calling IntersectRect) to enlarge your source rect if you also want to also find rects that are close but not overlapping.




Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Aug 13 2014 :  02:29:32  Show Profile  Reply
Hi Nigel,

Thanks for InflateRect. That might come in handy.

Andy
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: