answered Aug 8 '13
i think that you should have a look at the floodfill, watershed and grabcut algorithms. There is also an example in this book.