See Generating a Difference Matte.
The Difference Matte node generates a matte clip from a source clip and a background. This allows you to remove an image from one context and add it to another. The matte is created using the Tolerance and Softness values that you specify.This node supports floating-point (OpenEXR) clip input.