Tuesday, October 18, 2011

Using "snakes" to visually find object boundaries

Looking at an image and figuring out where the boundaries are of each object is a hard problem.  Here I have implemented a technique that can find object boundaries within either images or videos. 

The idea, described in this paper1, begins by physically modeling a flexible metal wire (like a guitar string) and placing that wire overtop of the image.  The program then generates "pushes" onto the wire based on what sort of image features are near it (such as bright areas or sudden brightness changes).  Those pushes gradually stretch the wire into different positions.  In the end, the stretched wire sits somewhere that serves as a reasonable boundary between two objects.

Computer vision scientists call this technique "snakes" or "active countours". The paper also used a math trick called dynamic programming to model the wire's energy - this trick finds the best possible rearrangement of the wire at each moment, and applying it takes relatively few computation steps.

This sort of thing is useful if you want to, say, select and cut out an entire object that moves around in a video.

The Demo:
(Special thanks goes to my friend Chenfanfu for recording these videos)

Here my program tries to find edges on a difficult image of the sun's corona. It works in an adaptive way while the user drags their mouse. You can see that it can usually compensate even when the user is very sloppy when pointing at their desired boundary:


Here it finds the boundary of an object in a video. The elastic "snake" continues to stretch to fit the boundary it found even as the object moves and deforms:


 


Here you can look at my code.  You can also try running it if you install OpenCV 2.2 on your computer first.

I believe that makes this the world's first complete open-source implementation of Dynamic Programming Snakes to hit the internet (others that I found online either had bugs or lacked the difficult "thin plate" term in the energy equation).

Here is my team's detailed report, which additionally includes my teammates' alternative implementation that instead uses a Greedy method to compute the snake's next move. Their videos are here.

1 "Using Dynamic Programming for Minimizing the Energy of Active Contours in the Presence of Hard Constraints", A. Amini, S. Tehrani, and T. Weymouth

No comments:

Post a Comment