Please see my comment to the question. In the meanwhile, please read:
If this is what you need: this is not a simple task at all; it's very hard to advise anything definitive in a quick Questions & Answers forum. You would need to seriously study this problem.
Maybe this is something else? :-)
This is quite problematic stuff. "Extract" sounds a bit naive. Try to search: http://bit.ly/JdIWwo