It's almost impossible to do this really convincingly in general in software, because the edges are blurred together, not a crisp edge.
The best way is with a very strong flash lighting, such that the ambient light is insignificant by comparison, and the foreground is the only thing that's exposed at all, in-camera.
Wow that looks great I love it. What program are you using?