Reputation: 91
I developed an algorithm for border tracing of objects in an image. The algorithm is capable of tracing all the objects in an image and returns the result so that you don't have to slice an image with multiple objects to use them with the algorithm.
So basically I begin by finding a threshold value, then get the binary image after threshold and then run the algorithm on it.
The algorithm is below:
This algorithm worked perfectly with objects that are far from each other, but when I tried with the image attached, I got the result attached also.
The problem is that, the square is near the circle and part of it lies in the square that contains the object, so this part is deleted because the program thinks that it is part of the first object.
I would appreciate it if anyone has a solution to this issue.
Thanks!
Upvotes: 1
Views: 1322
Reputation: 11339
A quick-and-dirty method is to sort the bounding boxes in ascending order by area before erasing the shapes. That way smaller shapes are removed first, which will reduce the number of overlapping objects. This will be sufficient if you have only convex shapes.
Pseudocode:
calculate all bounding boxes of shapes
sort boxes by area (smallest area first)
foreach box in list:
foreach pixel in box:
set pixel to 0
A method guaranteed to work for arbitrary shapes is to fill the box using a mask of the object. You already create a binary image, so you can use this as the mask.
Pseudocode:
foreach box in list:
foreach pixel in box:
if (pixel in mask == white): set pixel to 0
Upvotes: 1
Reputation: 6887
You can try using the canny edge detection technique for resolving this issue.
You can find more about it in the following URL,
http://homepages.inf.ed.ac.uk/rbf/HIPR2/canny.htm
Regards
Shiva
Upvotes: 1