Random object detection matlab

1.4k Views Asked by At

I want generate a random image using matlab which contains the object to be detected and the clutter images at random locations. I then want to detect this randomly generated object under the clutter images and outline the object based on the objects shape. I tried to look for code on mathworks but all I could find was to detect an object and draw a rectangular box around the detected object. What I want to do is to detect the object and draw the outline of the detected object.

Can anyone suggest me how to do this. Thanks

2

There are 2 best solutions below

0
On

You may want to take a look at "Marching Squares" Algorithm. A well documented example is located here: http://devblog.phillipspiess.com/2010/02/23/better-know-an-algorithm-1-marching-squares/
The coordinates you obtain from the algorithm can then again be used as coordinates on where to place the contour pixels in another image.

Unfortunately, I cannot provide you with any Matlab-Code (just ported it to Fortran), but given the discussion of the algorithm, it should be straightforward to implement it.
Some advice from my experience in using the "Marching Squares":

  1. For ease of programming the algorithm, turn the image into a black/white-image first. This provides a concise contour to be detected.
  2. The initial position is critical for the success of the process of detecting the contour. You may want to determine an approximate center of the object (i.e. a cluster) using some kind of filter function. From there you walk in one direction (North, South, West, East) until you hit the boundary and start the algorithm from there.

edit: Have you seen isocontour in MatlabCentral? http://www.mathworks.com/matlabcentral/fileexcahange/30525-isocontour

0
On

Try using the activecontour function from the Image Processing Toolbox.