Separating layers in images and its applications