Menshawi
Menshawi

Reputation: 91

performing border tracing on multiple objects in an image

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:

  1. find the first pixel that belongs to any object.
  2. Trace that object (has its own algorithm)
  3. get the minimum area of the square that contains that object
  4. mark all the pixels in that square as 0 (erase it from the binary image)
  5. repeat from 1 until there isn't any objects left.

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!enter image description here

Upvotes: 1

Views: 1322

Answers (2)

Aurelius
Aurelius

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

Shiva
Shiva

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

Related Questions